# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None
classSolution(object): defdeleteDuplicates(self, head): """ :type head: ListNode :rtype: ListNode """ dummy = pre = ListNode(0) dummy.next = head while head and head.next: if head.val == head.next.val: while head and head.next and head.val == head.next.val: head = head.next pre.next = head else: pre = pre.next head = head.next return dummy.next