Python short and simple solution


  • 0
    class Solution(object):
        def deleteDuplicates(self, head):
            dummy = ListNode(-1)
            dummy.next = head
            p = dummy
            while p.next:
                if p.next.next and p.next.val == p.next.next.val:
                    z = p.next
                    while z and z.val == p.next.val:
                        z = z.next
                    p.next = z
                else:
                    p = p.next
            return dummy.next

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.