083.Remove Duplicates from Sorted List

Solution 1: accepted 1ms

pointer - slow
next - fast

1
2
3
4
5
6
7
8
9
10
11
12
public ListNode deleteDuplicates(ListNode head) {
ListNode pointer = head;
while (pointer != null) {
ListNode next = pointer.next;
while (next != null && pointer.val == next.val) {
next = next.next;
}
pointer.next = next;
pointer = pointer.next;
}
return head;
}