← Back to problems Solve on LeetCode → See #98 Validate BST →

Search in a Binary Search Tree

LeetCode 700 • Easy • Trees

Input: root = [4,2,7,1,3], val = 2  →  Output: subtree rooted at 2
BST: go left if val < root.val, right if val > root.val.

TimeO(h)path height
SpaceO(1)pointer only
Current: 4
Current
Path / Found
Current
4
Ready
Press Play. While root and root.val!=val: go left if val<root.val, else right. Return root.