关键点
中序遍历输出看是不是有序的
代码
class Solution(object):
def isValidBST(self,root):
"""
:type root: TreeNode
:rtype: bool
"""
q=[]
def zcc(root):
if root.left!=None:
zcc(root.left)
q.append(root.val)
if root.right!=None:
zcc(root.right)
zcc(root)
if(q==sorted(q) and len(q)==len(set(q))):
return True
else:
return False