Problem
Given a sorted linked list, delete all duplicates such that each element appear only once.
Example 1:
1 |
|
Example 2:
1 |
|
Explanation
- We need a pointer that points to the first node of the linkedlist, then compare the first node’s value with the second node’s value. If they are the same, then delete the second node. Else, the pointer points at the second node. Repeat this process.
Solution
1 |
|