Remove Duplicates from Sorted List
Delete duplicates from a sorted list so each value appears once.
Open on LeetCode ↗Intuition
The instinct is to reach for a set of seen values, which works and is also the wrong lesson: the list is SORTED, so equal values are already neighbours and a set is memory you never needed. Compare each node against the one directly ahead of it and you have everything a set would have told you. The real slip is the pointer discipline. When you delete cur.next because it matches, the following node moves into that slot and might match too, so you must stay on cur and check again - advance unconditionally and [1,1,1] comes back as [1,1]. Note this problem keeps ONE copy of each value, unlike its harder sibling which removes every value that was ever duplicated; that difference decides whether a dummy node is needed at all. Here it is not, because the head is always kept.
Approach
Lean on the sorting
In a sorted list every group of equal values is contiguous. That means a single forward pass comparing cur.val with cur.next.val sees every duplicate, and no auxiliary structure is required. Recognising when the input's ordering already encodes the information is the transferable part.
Delete without advancing
If cur.next.val == cur.val, splice with cur.next = cur.next.next and loop again from the same cur. Only advance when the next value differs. Advancing after every step is the bug that leaves one duplicate behind in a run of three or more.
Return the original head
The head is always kept - it is the first occurrence of its own value - so no dummy node is needed and head is still correct at the end. This is the one case in the deletion family where you can safely skip the dummy.
Solution & live demo
Edge cases
Collapses to a single node.
The pointer advances every step and the list is unchanged.
Staying on cur after a deletion collapses the whole run.
The loop condition fails immediately; return head.