Accepted Python Solution


  • 0
    J
       class Solution:
            # @param head, a ListNode
            # @return a ListNode
            def deleteDuplicates(self, head):
                if not head:
                    return 
                dummy = ListNode(-1)
                dummy.next = head 
                prev = dummy
                slow = head
                fast  = slow
                count = 0
                while(fast):
                    if fast.val == slow.val:
                        fast = fast.next 
                        count+=1
                        continue 
                    if count > 1:
                        prev.next = fast
                        slow = fast
                        count=0
                    else:
                        prev = slow
                        slow = fast
                        count =0
                        
                if count > 1:
                    prev.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.