137. Remove Duplicates from Sorted List

Easy · Linked List

Given a sorted linked list, delete all duplicate nodes such that each unique value appears only once. The list should remain sorted after removal.

You are given the head of a sorted linked list. Return the head of the list after removing all duplicates.

Examples

Example 1
Input: [1, 1, 2]
Output: [1, 2]
Explanation: The duplicate 1 is removed, leaving only one occurrence of each value.
Example 2
Input: [1, 1, 1, 2, 3, 3]
Output: [1, 2, 3]
Explanation: All duplicates (three 1s become one, two 3s become one) are removed while maintaining sorted order.

Constraints