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
PreviousRoot Equals Sum of Children (Leetcode 2236)NextLowest Common Ancestor of a Binary Search Tree(BST) (Leetcode 235)
Last updated