Skip to content

Commit 23bfa4a

Browse files
Sean PrashadSean Prashad
authored andcommitted
Update 148_Sort_List.java
1 parent ecf1cce commit 23bfa4a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Fast & Slow Pointers/148_Sort_List.java

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

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

9-
while (fast != null && fast.next != null) {
10-
prev = slow;
11-
slow = slow.next;
12-
fast = fast.next.next;
9+
while (hare != null && hare.next != null) {
10+
prev = tortoise;
11+
tortoise = tortoise.next;
12+
hare = hare.next.next;
1313
}
1414

1515
prev.next = null;
1616

17-
ListNode l1 = sortList(head);
18-
ListNode l2 = sortList(slow);
17+
ListNode h1 = sortList(head);
18+
ListNode h2 = sortList(tortoise);
1919

20-
return merge(l1, l2);
20+
return merge(h1, h2);
2121
}
2222

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

0 commit comments

Comments
 (0)