The problem. Given the head of a sorted linked list, delete every duplicate so each value appears only once. Return the list, still sorted.
Input: head = [1, 1, 2]
Output: [1, 2]
Input: head = [1, 1, 2, 3, 3]
Output: [1, 2, 3]The word sorted is the hint. In a sorted list, all copies of a value sit next to each other.
Members only · free account
The rest of this lesson, with 5 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson