The problem. Given the root of a binary search tree and a key, delete the node with that value (if there is one) and return the root of the resulting BST. Any valid BST is accepted.
root = [5, 3, 6, 2, 4, null, 7], key = 3 -> [5, 4, 6, 2, null, null, 7]
root = [5, 3, 6, 2, 4, null, 7], key = 0 -> [5, 3, 6, 2, 4, null, 7] (not there)
root = [], key = 0 -> []Members only · free account
The rest of this lesson, with 6 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson