<reponame>Linchin/python_leetcode_git
"""
450
medium
delete node in BST

"""


# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

class Solution:
    def deleteNode(self, root, key):

        # search for the node
        node = root
        prev = None
        while node:
            if node.val == key:
                break
            elif node.val > key:
                prev = node
                dir = "left"
                node = node.left
            else:
                prev = node
                dir = "right"
                node = node.right

        if not node:
            return root

        new_root =



"""
450
medium
delete node in BST

"""


# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

class Solution:
    def deleteNode(self, root, key):

        # search for the node
        node = root
        prev = None
        while node:
            if node.val == key:
                break
            elif node.val > key:
                prev = node
                dir = "left"
                node = node.left
            else:
                prev = node
                dir = "right"
                node = node.right

        if not node:
            return root

        new_root =
450 medium delete node in BST # Definition for a binary tree node. # search for the node