Search in a Binary Search Tree
EasyTrees
Decode it first. Clues, constraints, pattern and plan before any code.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.
root = [4, 2, 7, 1, 3], val = 2 → [2, 1, 3]
root = [4, 2, 7, 1, 3], val = 5 → nullConstraints
1 <= number of nodes <= 50001 <= Node.val <= 10^7rootis a valid binary search tree.1 <= val <= 10^7