Leetcode Problem 700. Search in a Binary Search Tree

700. Search in a Binary Search Tree

Leetcode Solutions

Recursive Approach for Searching in a Binary Search Tree

  1. Check if the current node (root) is null. If it is, return null since the value cannot be found in an empty tree.
  2. If the value of the current node equals val, return the current node as the subtree rooted at this node is the answer.
  3. If val is less than the current node's value, recursively call searchBST on the left child.
  4. If val is greater than the current node's value, recursively call searchBST on the right child.
UML Thumbnail

Iterative Approach for Searching in a Binary Search Tree

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...