提交 578e4678 编写于 作者: L laozhang

add python 98

上级 0e9e0198
......@@ -18,7 +18,7 @@
4. [二叉搜索树中的搜索](./solution/tree/leetcode_700_.py)
5. [N叉树的后续遍历](./solution/tree/leetcode_590_.py)
6. [二叉树的层次遍历](./solution/tree/leetcode_32_.py)
7. [递增顺序查找二叉树](./solution/tree/leetcode_897_.py)
7. [递增顺序查找二叉树](./solution/tree/leetcode_897_.py)F
8. [单值二叉树](./solution/tree/leetcode_965_.py)
9. [二叉树的层次遍历II](./solution/tree/leetcode_107_.py)
10. [二叉树层的平均值](./solution/tree/leetcode_637_.py)
......@@ -60,6 +60,7 @@
46. [从前序与中序遍历序列构造二叉树](./solution/tree/leetcode_105_.py)
47. [二叉树的前序遍历](./solution/tree/leetcode_144_.py)
48. [N叉树的层序遍历](./solution/tree/leetcode_429_.py)
49. [验证二叉搜索树](./solution/tree/leetcode_98_.py)
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# coding=utf-8
"""
98. 验证二叉搜索树
"""
from solution import TreeNode
class Solution:
def isValidBST(self, root: TreeNode) -> bool:
temp = -2 ** 32
def dfs(root: TreeNode) -> bool:
nonlocal temp
if not root:
return True
a = dfs(root.left)
if root.val <= temp:
return False
temp = root.val
if a:
b = dfs(root.right)
return b
return a
return dfs(root)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册