Skip to content

visual walkthrough

Remove Duplicates from Sorted List

EasyPointer SkippingReported at: AmazonMetaMicrosoft+2

Basic pointer skipping on sorted data.

Solve on LeetCode

The idea

In a sorted list, duplicates are neighbours. So each node only needs to look at the one right after it.

To delete a node from a linked list, point the node before it past it: one arrow changes, nothing shifts.

Complexity

approachtimespace
Build a new listO(n)O(n)
Skip in placeO(n)O(1)

More walkthroughs