feat(0783_search-in-a-binary-search-tree): add python3 soln

This commit is contained in:
2022-04-05 21:47:41 +05:30
parent f28be89eb3
commit 27ed30d2a9
2 changed files with 45 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def searchBST(self, root: Optional[TreeNode], val: int) -> Optional[TreeNode]:
current = root
while current is not None:
if val == current.val:
return current
elif val < current.val:
current = current.left
else:
current = current.right
return None