Problem statement

https://binarysearch.com/problems/Search-in-a-Binary-Search-Tree/

Solution

Equal to Leetcode 0700. Search in a Binary Search Tree

Complexity

It is O(n) for time and O(h) for space.

Code

class Solution:
    def solve(self, root, val):
        if root == None:
            return False
        
        if val == root.val:
            return True
        
        if val < root.val:
            return self.solve(root.left, val)
        else:
            return self.solve(root.right,val)
        return False