Tap here to switch tabs
Problem
Submissions

Problem: Delete Node in a BST

Try to solve the Delete Node in a BST problem.

Statement

Given the root of a binary search tree and an integer key, remove the node with value key from the tree, and return the root of the updated binary search tree.

The deletion consists of two main stages:
11. Locate the node containing the value key.
22. If the node exists, delete it while maintaining the binary search tree property.

Constraints:

  • The number of nodes in the tree is in the range [0,104][0, 10^4].

  • −105≤-10^5 \leq Node.val ≤105\leq 10^5

  • Each node has a unique value.

  • root is a valid binary search tree.

  • −105≤-10^5 \leq key ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Delete Node in a BST

Try to solve the Delete Node in a BST problem.

Statement

Given the root of a binary search tree and an integer key, remove the node with value key from the tree, and return the root of the updated binary search tree.

The deletion consists of two main stages:
11. Locate the node containing the value key.
22. If the node exists, delete it while maintaining the binary search tree property.

Constraints:

  • The number of nodes in the tree is in the range [0,104][0, 10^4].

  • −105≤-10^5 \leq Node.val ≤105\leq 10^5

  • Each node has a unique value.

  • root is a valid binary search tree.

  • −105≤-10^5 \leq key ≤105\leq 10^5