parent
b87d619cdd
commit
6178dff832
|
|
@ -338,7 +338,7 @@ class Solution {
|
|||
|
||||
Python:
|
||||
|
||||
**递归** - 利用BST中序遍历特性
|
||||
**递归** - 利用BST中序遍历特性,把树"压缩"成数组
|
||||
```python
|
||||
# Definition for a binary tree node.
|
||||
# class TreeNode:
|
||||
|
|
@ -362,7 +362,7 @@ class Solution:
|
|||
|
||||
def __is_sorted(nums: list) -> bool:
|
||||
for i in range(1, len(nums)):
|
||||
if nums[i] <= nums[i - 1]:
|
||||
if nums[i] <= nums[i - 1]: # ⚠️ 注意: Leetcode定义二叉搜索树中不能有重复元素
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
@ -370,8 +370,11 @@ class Solution:
|
|||
res = __is_sorted(candidate_list)
|
||||
|
||||
return res
|
||||
```
|
||||
|
||||
# 简单递归法
|
||||
**递归** -
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def isValidBST(self, root: TreeNode) -> bool:
|
||||
def isBST(root, min_val, max_val):
|
||||
|
|
|
|||
Loading…
Reference in New Issue