diff --git a/problems/0098.验证二叉搜索树.md b/problems/0098.验证二叉搜索树.md index a271b977..cf8651f3 100644 --- a/problems/0098.验证二叉搜索树.md +++ b/problems/0098.验证二叉搜索树.md @@ -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):