15% off all plans & roadmaps Use code
See plansLeetCode 83 · Solution & editorial
Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.
Remove Duplicates from Sorted List is a Linked List Manipulation Patterns problem, in the In-place Reversal subpattern. The pattern covers in-place reversal, merging sorted lists, reordering, and intersection detection
Master in-place linked list reversal including full reversal, partial reversal, and k-group reversal techniques.
The reference solution runs in O(n) time and O(1) space.
Remove Duplicates from Sorted List has been reported in interviews at Amazon, Adobe, Goldman Sachs, Qualcomm.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Remove Duplicates from Sorted List is a Linked List Manipulation Patterns problem, in the In-place Reversal subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.