Given the head of a sorted linked list, your task is to remove all duplicate nodes so that each unique value appears only once in the final list.
Since the linked list is already sorted, all duplicate values will be consecutive, making this problem more manageable than if the duplicates were scattered throughout the list.
Goal: Return the head of the modified linked list with duplicates removed, maintaining the sorted order.
Example: If your linked list is 1 → 1 → 2 → 3 → 3, the result should be 1 → 2 → 3.
This is a fundamental linked list manipulation problem that tests your understanding of pointer manipulation and node traversal - essential skills for any software engineer!
Input & Output
Constraints
- The number of nodes in the list is in the range [0, 300]
- Each node's value is in the range [-100, 100]
- The list is guaranteed to be sorted in non-decreasing order