2.Search in a Binary Search Tree
Last updated
Was this helpful?
Last updated
Was this helpful?
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
.
You are given the root
of a binary search tree (BST) and an integer val
.
Example 1:
Example 2:
Maximum number of comparisons is h
i.e height of binary search tree
So time complexity O(h) i.e O(log n).