Problem Definition:
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
.
Solution : 值得注意的是递归解法:
1 def deleteDuplicates(head): 2 if head==None or head.next==None: 3 return head 4 head.next=self.deleteDuplicates(head.next) 5 return head.next if head.val==head.next.val else head