Python recursion, no dummy, one pointer, easy to understand


  • 0
    class Solution(object):
        def deleteDuplicates(self, head):
            if head == None: return None
            node = head
            flag = 0
            while node.next and node.val == node.next.val:
                flag = 1
                node.next = node.next.next
            head.next = self.deleteDuplicates(node.next)
            return head if not flag else head.next 
    

Log in to reply
 

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