My in-order solution


  • 0
    class Solution(object):
        def isValidBST(self, root):
            stack, inorder = [], []
            while root:
                stack.append(root)
                root = root.left
            while stack:
                top = stack.pop()
                inorder.append(top.val)
                tmp = top.right
                while tmp:
                    stack.append(tmp)
                    tmp = tmp.left
            for i in xrange(1, len(inorder)):
                if inorder[i] <= inorder[i - 1]:
                    return False
            return True
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.