Problem
You are given the root of a binary search tree (every node is larger than everything in its left subtree and smaller than everything in its right subtree) and a value val.
Find the node whose value equals val and return the subtree rooted at that node. If no node has that value, return None (null in TypeScript).
Trees in the examples are written in level order (top to bottom, left to right), with null for a missing child, the same way the tests build them.
Example 1
- Input
- root = [4, 2, 7, 1, 3], val = 2
- Output
- [2, 1, 3]
Example 2
- Input
- root = [4, 2, 7, 1, 3], val = 5
- Output
- null
Constraints
1 <= number of nodes <= 50001 <= Node.val <= 10^7root is a valid binary search tree.1 <= val <= 10^7