Leetcode Problem 83. Remove Duplicates from Sorted List
83. Remove Duplicates from Sorted List
Leetcode Solutions
Removing Duplicates from a Sorted Linked List
Check if the head is null or the list has only one node. If true, return the head as is.
Initialize a pointer current to the head of the list.
While current and current.next are not null:
a. If current.val is equal to current.next.val, set current.next to current.next.next to remove the duplicate.
b. Otherwise, move current to the next node.
Return the modified list starting from the head.
Collecting Unique Elements and Reconstructing the Linked List