← Back to DSA Animator
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.valcurr.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.