Remove Duplicates from a Sorted Doubly Linked List
Implement removeDupSortedDLL
Given the head of a doubly linked list already sorted in non-decreasing order, remove all duplicate values so each distinct value appears exactly once — keeping the list's relative order — and return the head.
Since the list is sorted, duplicates are never scattered — they're always neighbors. That means each node only ever needs to check the one node right after it: no hash set or extra pass is needed to know whether a value has been seen before, unlike the unsorted "delete all occurrences of a key" problem.
Example 1:
Input: head = [1,1,2,3,3,3,7,9,9]
Output: [1,2,3,7,9]
Example 2:
Input: head = [2,2,2]
Output: [2]
Example 3:
Input: head = [1,2,3]
Output: [1,2,3]
+ 3 hidden test cases run on Submit.
Constraints:
- ●
0 ≤ number of nodes in head ≤ 200 - ●
-1000 ≤ node value ≤ 1000 - ●
head is already sorted in non-decreasing order, so every duplicate of a value sits consecutively
head =
[1, 1, 2, 3, 3, 3, 7, 9, 9]