2
* Definition for a binary tree node.3
* function TreeNode(val, left, right) {4
* this.val = (val===undefined ? 0 : val)5
* this.left = (left===undefined ? null : left)6
* this.right = (right===undefined ? null : right)10
const getLeftMostNode = (root) => {11
if (!root) return null;12
let node = getLeftMostNode(root.left);13
return node ? node : root;16
* @param {TreeNode} root21
var deleteNode = function (root, key) {22
if (!root) return null;24
root.left = deleteNode(root.left, key);25
} else if (root.val < key) {26
root.right = deleteNode(root.right, key);28
if (!root.left) return root.right;29
if (!root.right) return root.left;30
let succ_node = getLeftMostNode(root.right);31
root.val = succ_node.val;32
root.right = deleteNode(root.right, succ_node.val);