时间复杂度(O(n)),思想:中序遍历
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def isValidBST(self, root: TreeNode) -> bool:
def searchT(root: TreeNode, l: []):
if root is None: return
searchT(root.left, l)
if l[0] is not None and l[0] >= root.val: l[1] = False
if l[1] is False: return
l[0] = root.val
searchT(root.right, l)
l = [None, True]
searchT(root, l)
return l[1]