python solution


  • 0
    J
    class Solution(object):
        def deleteNode(self, root, key):
            if root is None:
                return root
            if key < root.val:
                root.left = self.deleteNode(root.left, key)
            elif key > root.val:
                root.right = self.deleteNode(root.right, key)
            elif root.left is None:
                return root.right
            elif root.right is None:
                return root.left
            else:
                min = root.right
                while(min.left is not None):
                    min = min.left
                min.left = root.left
                return root.right
            return root
    

Log in to reply
 

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