Remove Repeats from Sorted List

Easy

Question

Given the head of a sorted linked list, delete all repeats and return the manipulated linked list. The returned linked list should still be sorted.

Try to solve this problem in O(n) time and O(1) space.

Remove Repeats from Sorted List Example 1

Input: head = [1 -> 1 -> 2 -> 3 -> 3]

Remove Repeats from Sorted List Example 1

Output: [1 -> 2 -> 3]

Remove Repeats from Sorted List Example 2

Input: head = [5 -> 5 -> 5]

Remove Repeats from Sorted List Example 2

Output: [5]

Clarify the problem

What are some questions you'd ask an interviewer?

Understand the problem

What is the resulting list after removing all repeats from the following sorted list? head = [4 -> 7 -> 8 -> 8 -> 9 -> 10 -> 11 -> 11 -> 11 -> 15 -> 15 -> 20]
[4 -> 7 -> 9 -> 10 -> 20]
[20 -> 10 -> 9 -> 7 -> 4]
[4 -> 7 -> 8 -> 9 -> 10 -> 11 -> 15 -> 20]
[20 -> 15 -> 11 -> 10 -> 9 -> 8 -> 7 -> 4]

Login or signup to save your code.

Notes