98-Validate Binary Search Tree

Title: verify whether a binary tree binary sort tree

def isValidBST(root):
    inorder = inorder(root)
    return inorder == list(sorted(set(inorder)))
def inorder(root):
    if root is None:
        return []
    return inorder(root.left) + [root.val] +inorder(root.right)

Note:

Using preorder traversal of a binary tree, if the result is sorted, it indicates that the binary sort tree is a binary tree

Guess you like

Origin www.cnblogs.com/kingshine007/p/11372974.html