From 6178dff832cebd336c596ae40ae941ab28cd42c2 Mon Sep 17 00:00:00 2001 From: Kelvin Date: Sun, 1 Aug 2021 13:57:12 -0400 Subject: [PATCH] =?UTF-8?q?Update=200098.=E9=AA=8C=E8=AF=81=E4=BA=8C?= =?UTF-8?q?=E5=8F=89=E6=90=9C=E7=B4=A2=E6=A0=91.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加comment --- problems/0098.验证二叉搜索树.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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):