Remove Duplicates from a Sorted Doubly Linked List

You are given the head of a sorted (ascending) doubly linked list. Every node carries an integer value, a forward link (next) to the following node, and a…

You are given the head of a sorted (ascending) doubly linked list. Every node carries an integer value, a forward link (`next`) to the following node, and a backward link (`prev`) to the preceding node, with both ends terminating in `null`. Remove all nodes that hold a value already seen earlier in the list so each value appears exactly once, and return the head of the deduplicated list. Because the list is sorted, all copies of the same value appear consecutively — a single O(n) forward pass with a `current` pointer is enough. At each position, if the next node holds the same value as the current node, unlink the next node by rewiring `current.next` and updating the backward link of the node beyond it; otherwise advance `current`. For example, with `head = [1, 1, 2, 3, 3, 4]`, the result is `[1, 2, 3, 4]`.

- The number of nodes `n` satisfies `0 <= n <= 10^5`. - Each node value lies in the range `-10^9 <= node.val <= 10^9`. - The list is sorted in non-decreasing (ascending) order. - Duplicate removal must run in O(n) time and O(1) extra space.

Example 1: input head = [1,1,2,3,3,4]; output [1, 2, 3, 4]. The second 1 and the second 3 are adjacent duplicates that are unlinked in a single forward pass.

Example 2: input head = [5,5,5,5]; output [5]. All four nodes hold 5; only the first survives after the other three are unlinked.

Example 3: input head = [1,2,3]; output [1, 2, 3]. No adjacent duplicates — the list is already unique.

Category: Linked List. Topic: linked-list. Difficulty: Easy. Patterns: linked-list-traversal.