给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字,比如:
输入: 1->2->3->3->4->4->5
输出: 1->2->5
def deleteDuplicates(self, head: ListNode) -> ListNode:
dummynode = ListNode(None)
dummynode.next = head
pre = dummynode
while pre.next:
cur = pre.next
if cur.next and cur.val == cur.next.val:
while cur.next and cur.val == cur.next.val:
cur = cur.next
pre.next = cur.next
else:
pre = pre.next
return dummynode.next