class Solution(object): def inorderTraversal(self, root, inorder): if root: self.inorderTraversal(root.left, inorder) inorder.append(root.val) self.inorderTraversal(root.right, inorder) def isValidBST(self, root): """ :type root: TreeNode :rtype: bool """ if not root: return True # if not root.left or not root.right: # return True inorder = [] self.inorderTraversal(root, inorder) for i in range(len(inorder)-1): if inorder[i] >= inorder[i+1]: return False return True