DSA AnimatorDSA animations
Remove Duplicates from Sorted List LC #83 Easy Linked List · In-Place
Problem

Given the head of a sorted linked list, delete all duplicates so that each element appears only once. Return the modified list head (still sorted).

Example 1
Input: head = [1,1,2]
Output: [1,2]
Example 2
Input: head = [1,1,2,3,3]
Output: [1,2,3]
Constraints: 0 ≤ list length ≤ 300  |  −100 ≤ Node.val ≤ 100  |  List is sorted ascending
Try Examples
Custom:
List Visualization
Variables
curr.val
—
curr.next.val
—
Action
—
Step Logic
Press ▶ Play or Next Step to begin.
✅
Ready
0 / 0
Select an example above and press Play.
Algorithm
1
Set curr = head.
2
Loop while curr != null && curr.next != null.
3
Duplicate: curr.val == curr.next.val → curr.next = curr.next.next. Stay at curr.
4
Unique: advance curr = curr.next.
5
Return head.
Time
O(n)
Space
O(1)
Key Insight

Because the list is already sorted, all duplicates of a value are adjacent. We rewire curr.next to skip over the duplicate node — O(1) pointer update, no extra memory. The skip arc shows exactly which pointer is redirected. curr never moves backward; it either stays (if the next node was a duplicate that got unlinked) or advances forward.

How to solve Remove Duplicates from Sorted List

LeetCode 83 · Easy · Linked List · Pattern: Linked List Traversal

Why the obvious approach is slow

Copying values into a set and building a new list uses extra space. The list is sorted, so duplicates sit next to each other.

The key idea

Walk with one pointer, current. If the next node has the same value, skip it by linking current to the node after it. Otherwise, move current forward.

Remember

In a sorted list, duplicates are neighbours. Skip the next node instead of moving when values match.

Run the animation above on your own input, or watch the 1:06 video explanation of Remove Duplicates from Sorted List with a dry run and Java code.

More Linked List problems