题目:
题解:
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = Noneclass Solution(object):def isValidBST(self, root):""":type root: TreeNode:rtype: bool"""pre = -float('inf')p = rootst = []while p is not None or st:while p is not None:st.append(p)p = p.leftp = st.pop()if p.val > pre:pre = p.valelse:return Falsep = p.rightreturn True