The problem. Given the root of a binary search tree and an integer val, find the node whose value is val and return the subtree rooted at that node. If there's no such node, return null.
root = [4, 2, 7, 1, 3], val = 2 -> [2, 1, 3]
root = [4, 2, 7, 1, 3], val = 5 -> [] (null: 5 isn't in the tree)
root = [4, 2, 7, 1, 3], val = 4 -> [4, 2, 7, 1, 3]Members only · free account
The rest of this lesson, with 7 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