给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。
示例 1:
输入: 1->1->2 输出: 1->2
示例 2:
输入: 1->1->2->3->3 输出: 1->2->3
class Solution(object):
def deleteDuplicates(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
print head
if head == None :
return None
if head.next == None:
return head
a = head
b=a.next
while b :
if a.val == b.val and b.next==None:
a.next = None
break
elif a.val == b.val:
a.next = b.next
b = b.next
elif b.next:
a = a.next
b = b.next
else :
break
return head