# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None
classSolution: # @param head, a ListNode # @return a ListNode defdeleteDuplicates(self, head): dummy=ListNode(-1) dummy.next=head cur=dummy.next while cur and cur.next: if cur.val==cur.next.val: cur.next=cur.next.next else: cur=cur.next return dummy.next