Practice Delete Node in a BST
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
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: Example 1: Example 2: Example 3: Constraints: Follow up: Could you solve it with time complexity O(height of tree)?
Source: Delete Node in a BST on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
root = [5,3,6,2,4,null,7], key = 3
Output
[5,4,6,2,null,null,7]
# Example 2
Input
root = [5,3,6,2,4,null,7], key = 0
Output
[5,3,6,2,4,null,7]
# Example 3
Input
root = [], key = 0
Output
[]
Constraints
The number of nodes in the tree is in the range [0, 10^4].
-10^5 <= Node.val <= 10^5
Each node has a unique value.
root is a valid binary search tree.
-10^5 <= key <= 10^5
Related LeetCode Problems
Practice more problems similar to Delete Node in a BST.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.