Problem
Given a sorted linked list, delete all duplicates such that each element appear only once.
Examples
1 | Input: 1->1->2 |
Solution
Method: Two Pointers
Time Complexity: O(n)
Space Complexity: O(1)
1 | class Solution: |
Note
Don’t forget to check the boundary condition. For example:
1 | Input: 1->2->3 |
1 | Input: 1->2->2 |