Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well.
Example 1
Input: head = [1,2,3,3,4,4,5]
Output: [1,2,5]
Explanation: 3 and 4 each appear more than once, so every copy of them is removed. Only 1, 2 and 5 were unique.
Example 2
Input: head = [1,1,1,2,3]
Output: [2,3]
Explanation: 1 appears three times, so all three copies are removed, leaving [2,3].
Example 3
Input: head = [1,2,3]
Output: [1,2,3]
Explanation: Every value appears once, so the list is unchanged.
Because the list is sorted, duplicates are consecutive. Keep a pointer to the last confirmed-unique node; whenever the node ahead starts a run of equal values, skip the entire run so no copy remains. A dummy head handles deletions at the front.
Run checks all cases above. Submit evaluates all test cases.