#83

Remove Duplicates from Sorted List

Easy In-place unlink

  1. Read
  2. Understand
  3. Hints
  4. Approach
  5. Solution
  6. Solved

?The problem

Delete duplicate nodes from a sorted linked list so each value appears once.

This is a short summary in our own words. Read the full statement and examples on LeetCode: open problem ↗

◎Understanding

Really asking: keep one node per value in a sorted list.

Why this works: duplicates sit together; skip cur.next while it repeats cur's value.

Example: 1 → 1 → 2 → 3 → 3

skip second 1, skip second 3 → 1 → 2 → 3

✦Hints open one at a time

↗Approach

</>Solution (Java)

!Common mistake

Moving cur forward after unlinking, which misses a third copy.

Solve on LeetCode ↗
Complexity
  • Time: O(n).
  • Space: O(1).
Topic: Linked List
🎬 Episodes 40–45: video coming soon