mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update 0098.验证二叉搜索树.md
增加comment
This commit is contained in:
@ -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):
|
||||
|
Reference in New Issue
Block a user