Given the head of a sorted linked list, delete all duplicates so that
each element appears only once. Return the modified list head (still sorted).
head = [1,1,2][1,2]head = [1,1,2,3,3][1,2,3]curr = head.curr != null && curr.next != null.curr.val == curr.next.val → curr.next = curr.next.next. Stay at curr.curr = curr.next.head.
Because the list is already sorted, all duplicates of a value are
adjacent. We rewire curr.next to skip over the duplicate node — O(1) pointer update,
no extra memory. The skip arc shows exactly which pointer is redirected. curr never moves backward;
it either stays (if the next node was a duplicate that got unlinked) or advances forward.
Copying values into a set and building a new list uses extra space. The list is sorted, so duplicates sit next to each other.
Walk with one pointer, current. If the next node has the same value, skip it by linking current to the node after it. Otherwise, move current forward.
In a sorted list, duplicates are neighbours. Skip the next node instead of moving when values match.
Run the animation above on your own input, or watch the 1:06 video explanation of Remove Duplicates from Sorted List with a dry run and Java code.