Skip to content

Commit 9258346

Browse files
Sean PrashadSean Prashad
authored andcommitted
Update 83_Remove_Duplicates_from_Sorted_List.java
1 parent f8209ce commit 9258346

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Two Pointers/83_Remove_Duplicates_from_Sorted_List.java

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

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

99
while (curr != null) {
10-
while (fast != null && curr.val == fast.val) {
11-
fast = fast.next;
10+
if (curr.next == null) {
11+
break;
1212
}
1313

14-
curr.next = fast;
15-
curr = fast;
14+
if (curr.val == curr.next.val) {
15+
curr.next = curr.next.next;
16+
} else {
17+
curr = curr.next;
18+
}
1619
}
1720

1821
return head;

0 commit comments

Comments
 (0)