loading

Remove Duplicates from Sorted List II — Step-by-Step Visualization

mediumLeetCode #82Linked ListTwo Pointers

Delete all nodes with duplicate numbers from sorted linked list, leaving only distinct numbers.

Algorithm Pattern

Dummy Node Skip

Key Idea

When duplicates detected, skip the entire group by linking prev directly to the node after the group.

Step-by-Step Approach

  1. Create dummy before head
  2. If curr.val == curr.next.val, skip entire duplicate group
  3. Otherwise advance prev
  4. Always advance curr

Related Problems