Skip to content

Commit 3250d5a

Browse files
Sean PrashadSean Prashad
authored andcommitted
Update 148_Sort_List.java
1 parent b4a76f3 commit 3250d5a

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

Fast & Slow Pointers/148_Sort_List.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public ListNode sortList(ListNode head) {
44
return head;
55
}
66

7-
ListNode tortoise = head, hare = head, prev = tortoise;
7+
ListNode tortoise = head, hare = head, prev = null;
88

99
while (hare != null && hare.next != null) {
1010
prev = tortoise;
@@ -14,10 +14,7 @@ public ListNode sortList(ListNode head) {
1414

1515
prev.next = null;
1616

17-
ListNode h1 = sortList(head);
18-
ListNode h2 = sortList(tortoise);
19-
20-
return merge(h1, h2);
17+
return merge(sortList(head), sortList(tortoise));
2118
}
2219

2320
private ListNode merge(ListNode l1, ListNode l2) {

0 commit comments

Comments
 (0)