给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字。
示例 1:
输入: 1->2->3->3->4->4->5 输出: 1->2->5
示例 2:
输入: 1->1->1->2->3 输出: 2->3
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def deleteDuplicates(self, head):
if not head or not head.next: return head
dummy = ListNode(-1)
dummy.next = head
temp = dummy
while temp.next.next != None:
if temp.next.val == temp.next.next.val:
temp1 = temp.next.next
while temp1.next != None and temp1.next.val == temp.next.val:
temp1 = temp1.next
temp.next =temp1.next
if temp.next == None: break
else: temp = temp.next
return dummy.next