We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b4a76f3 commit 3250d5aCopy full SHA for 3250d5a
Fast & Slow Pointers/148_Sort_List.java
@@ -4,7 +4,7 @@ public ListNode sortList(ListNode head) {
4
return head;
5
}
6
7
- ListNode tortoise = head, hare = head, prev = tortoise;
+ ListNode tortoise = head, hare = head, prev = null;
8
9
while (hare != null && hare.next != null) {
10
prev = tortoise;
@@ -14,10 +14,7 @@ public ListNode sortList(ListNode head) {
14
15
prev.next = null;
16
17
- ListNode h1 = sortList(head);
18
- ListNode h2 = sortList(tortoise);
19
-
20
- return merge(h1, h2);
+ return merge(sortList(head), sortList(tortoise));
21
22
23
private ListNode merge(ListNode l1, ListNode l2) {
0 commit comments