Skip to interview prep
Apexed

23. Remove Duplicates From a Sorted List

EasyLinked lists

A linked list is sorted in non-decreasing order. Remove duplicate nodes so that each value appears once, and return the head.

A linked list is passed as ListNode objects with val and next. The tests write lists as arrays.

Example 1

Input: head = [1, 1, 2, 3, 3]
Output: [1, 2, 3]

Constraints

  • 0 ≤ nodes ≤ 300

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Remove Duplicates From a Sorted List — coding interview practice — Apexed