Skip to content

Commit d73042b

Browse files
Sean PrashadSean Prashad
authored andcommitted
Move 83_Remove_Duplicates_from_Sorted_List.java into Fast & Slow
Pointers
1 parent 92df005 commit d73042b

File tree

2 files changed

+8
-28
lines changed

2 files changed

+8
-28
lines changed

Fast & Slow Pointers/83_Remove_Duplicates_from_Sorted_List.java

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

7-
ListNode curr = head, fast = head.next;
7+
ListNode curr = head, prev = head;
88

99
while (curr != null) {
10-
while (fast != null && curr.val == fast.val) {
11-
fast = fast.next;
10+
if (prev.val == curr.val) {
11+
curr = curr.next;
12+
} else {
13+
prev.next = curr;
14+
prev = prev.next;
1215
}
13-
14-
curr.next = fast;
15-
curr = fast;
1616
}
1717

18+
prev.next = curr;
19+
1820
return head;
1921
}
2022
}

Two Pointers/83_Remove_Duplicates_from_Sorted_List.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)