Remove Duplicates from Sorted List
Problem
Given a sorted linked list, delete all duplicates such that each element appear only once.
Example
Given 1->1->2
, return 1->2
.
Given 1->1->2->3->3
, return 1->2->3
.
Solutions
An easy problem.
If the value of the next node is the same as the current node, simply skip the next node.
Since all values will be preserved, we can start from the head
node, without using a dummy node at the beginning.
Check out Remove Duplicates from Sorted List II for a slightly more challenging variation.