#700
Search in a Binary Search Tree
newbie · 145 · lc easy +13 · verified · 82.5% accepted · 6,549 likes · top 94%
Description
Given the root of a binary search tree (BST) and an integer val, locate the node whose value equals val and return the subtree rooted at that node. If no such node exists, return null.
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: []
Code
1
2
3
4
5
6
7
8
9