给定一个排序链表,删除所有重复的元素每个元素只留下一个。
链表的基本操作不多解释
def deleteDuplicates(self, head):
if not head:
return head
cur = head.next
pre = head
while cur:
if cur.val == pre.val:
cur = cur.next
else:
pre.next = cur
pre = cur
cur = cur.next
pre.next = None
return head