Search in a Binary Search Tree(BST) (Leetcode 700)

Problem Link: https://leetcode.com/problems/search-in-a-binary-search-tree/

class Solution:

    def searchBST(self, root: Optional[TreeNode], val: int) -> Optional[TreeNode]:
    
        while(root is not None):
            if(root.val==val):
                return root
            elif(root.val<val):
                root=root.right
            else:
                root=root.left
        return root

Last updated