mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2026-05-11 10:33:22 +08:00
Update 0700.二叉搜索树中的搜索.md
This commit is contained in:
@@ -230,7 +230,7 @@ class Solution {
|
|||||||
|
|
||||||
### Python
|
### Python
|
||||||
|
|
||||||
递归法:
|
(方法一) 递归
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class Solution:
|
class Solution:
|
||||||
@@ -250,12 +250,12 @@ class Solution:
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
迭代法:
|
(方法二)迭代
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class Solution:
|
class Solution:
|
||||||
def searchBST(self, root: TreeNode, val: int) -> TreeNode:
|
def searchBST(self, root: TreeNode, val: int) -> TreeNode:
|
||||||
while root is not None:
|
while root:
|
||||||
if val < root.val: root = root.left
|
if val < root.val: root = root.left
|
||||||
elif val > root.val: root = root.right
|
elif val > root.val: root = root.right
|
||||||
else: return root
|
else: return root
|
||||||
|
|||||||
Reference in New Issue
Block a user