You are given the root of a binary search tree (BST) and an integer val. Find the node in the BST that the node's value equals val and return the subtree rooted with that node. If such a node does not exist, return null.
Example 1
Input: root = [4,2,7,1,3], val = 2
Output: [2,1,3]
Explanation: 2 is smaller than the root 4, so we go left and find 2 right away. Its subtree is 2 with children 1 and 3.
Example 2
Input: root = [4,2,7,1,3], val = 5
Output: []
Explanation: 5 is larger than 4, so we go right to 7. 5 is smaller than 7, but 7 has no left child, so 5 is not in the tree.
Example 3
Input: root = [1], val = 1
Output: [1]
Explanation: The root itself holds 1, so the whole tree is returned.
Use the BST ordering: at each node go left if val is smaller, right if larger, stop when equal or off the tree.
Run checks all cases above. Submit evaluates all test cases.