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]
Example 2:
Input: head = [1,1,1,2,3]
Output: [2,3]
1 of 4
What is the optimal approach for this problem?
A. Use a dummy node before head. When a duplicate group is found, skip all nodes with that value by advancing curr, then link prev.next past the group. If no duplicate, advance prev normally. Both approaches are O(n).B. Use recursion: if head.val == head.next.val, skip ahead until value changes, then recurse on rest.C. Count occurrences of each value using a pass, then rebuild the list keeping only values with count 1.D. Use a hash set to record which values have duplicates, then rebuild the list excluding those values.