Skip to content

Commit 1bfaff3

Browse files
Alimov-8Alimov-8
Alimov-8
authored and
Alimov-8
committed
700
1 parent fd7725e commit 1bfaff3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Leetocode 700. Search in a Binary Search Tree
2+
3+
4+
### Runtime: 106 ms, faster than 52.69% of Python3
5+
6+
<br>
7+
8+
```py
9+
# Definition for a binary tree node.
10+
# class TreeNode:
11+
# def __init__(self, val=0, left=None, right=None):
12+
# self.val = val
13+
# self.left = left
14+
# self.right = right
15+
16+
class Solution:
17+
def searchBST(self, root: Optional[TreeNode], val: int) -> Optional[TreeNode]:
18+
def find(root, val):
19+
if not root:
20+
return None
21+
22+
if root.val == val:
23+
return root
24+
25+
if root.right:
26+
if val > root.val:
27+
return find(root.right, val)
28+
29+
if root.left:
30+
if val < root.val:
31+
return find(root.left, val)
32+
33+
34+
return find(root, val)
35+
```

Data Structure 1/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@
5656

5757
- [566. Reshape Matrix -Array](https://github.com/Alimov-8/leetcode-solutions/blob/master/Data%20Structure%201/566.%20Reshape%20Matrix.md#leetcode-566-reshape-matrix)
5858

59+
- [700. Search in a Binary Search Tree - Tree](https://github.com/Alimov-8/leetcode-solutions/blob/master/Data%20Structure%201)
60+

0 commit comments

Comments
 (0)