Tuesday, March 5, 2013

Remove Duplicates from Sorted List


Remove Duplicates from Sorted ListApr 22 '12
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.
Analysis
This is a O(n) time complexity algorithm that links the last distinct element with the current distinct element, thereby deleting all elements between these two nodes.

No comments:

Post a Comment