当前位置:网站首页>判断是否二叉搜索树
判断是否二叉搜索树
2022-07-21 11:30:00 【咕噜咕噜day】
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param root TreeNode类
# @return bool布尔型
#
import sys
class Solution:
def isValidBST(self , root: TreeNode) -> bool:
# write code here
# 根据中序遍历的值来判断,递归base项是 判断当前根节点的值与左子树的值的大小关系。
def recur(root):
if not root:
return True
if not recur(root.left):
return False
if root.val <= self.pre:
return False
self.pre = root.val # 更新最值,self.pre
if not recur(root.right):
return False
return True
self.pre = -sys.maxsize -1
return recur(root)
边栏推荐
猜你喜欢
随机推荐
论文阅读:CTRL: A CONDITIONAL TRANSFORMER LANGUAGE MODEL FOR CONTROLLABLE GENERATION
gadget之udc
【CCF CSP】201803-1跳一跳
薅羊毛的最高境界,解放你的双手
严蔚敏第二章课后习题(2.29-2.38)
静态方法与实例方法的区别
gadget之composite
获取模块句柄/基址
PWN的学习
Li Shuo, vice president of Baidu: AI can go deep into the scene and create real value. From sensors to large screens, it is just the beginning of digitalization
5.1 identity authentication
压缩字符串
Natural language Processing in tensorflow quizs on Coursera
Yan Weimin Chapter II after class exercises (2.29-2.38)
[39题] 牛客深度学习专项题
【CCF CSP】201712-1最小差值
He has been in charge of the British Society of engineering and technology for 13 years, and van nugget officially retired
Clean up SYSTEMd logs
Yan Weimin Chapter II answers to exercises after class
Serial Vector Format(SVF)文件格式