0450. Delete Node in a BST
https://leetcode.com/problems/delete-node-in-a-bst
Description
Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.
Basically, the deletion can be divided into two stages:
Search for a node to remove.
If the node is found, delete the node.
Follow up: Can you solve it with time complexity O(height of tree)?
Example 1:

Example 2:
Example 3:
Constraints:
The number of nodes in the tree is in the range
[0, 104].-105 <= Node.val <= 105Each node has a unique value.
rootis a valid binary search tree.-105 <= key <= 105
ac
Last updated
Was this helpful?