clean python solution involving dummy node


  • 0
    I
    class Solution(object):
        def deleteDuplicates(self, head):
            """
            :type head: ListNode
            :rtype: ListNode
            """
            dummy = ListNode(-1)
            dummy.next = head
            prev, curr = dummy, dummy.next
            
            while curr:
                if curr.next and curr.val == curr.next.val:
                    val_to_rem = curr.val
                    
                    while curr and curr.val == val_to_rem:
                        curr = curr.next
                        
                    prev.next = curr
                    
                else:
                    prev, curr = curr, curr.next
                    
            return dummy.next

Log in to reply
 

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