Simple Accepted Python Solution

  • 0
    class Solution:
        def deleteDuplicates(self, head):
            virtual = ListNode(-1111)   # some dummy vaue as the header
   = head
            dummy_head = virtual  # dummy head, always point to the header
            flag = False
            while virtual is not None:
                if is None:
                cur =
                while is not None and cur.val ==
                   flag = True
                if not flag:
                    # if no duplicated value in this round of searching, proceed to the next one
                    virtual =
                    # if there is duplicated value, change the next pointer
                flag = False

Log in to reply

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