9 lines. One pass Python using set


  • 0
    L
        def deleteDuplicates(self, head):
            seen = set()
            dummy = dummyRunner = ListNode(0)
            current = head
            while current :
                if current.val not in seen and (not current.next or current.val != current.next.val) :
                    dummyRunner.next = current; dummyRunner = dummyRunner.next
                seen.add(current.val); current = current.next
            dummyRunner.next = None
            return dummy.next
    

Log in to reply
 

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