Python Inorder Solution with stack.[BEAT 82%]

  • 0
    class Solution(object):
        def isValidBST(self, root):
            :type root: TreeNode
            :rtype: bool
            stack = []
            curr = root
            prev = -0xFFFFFFFF
            while curr or stack:
                while curr:
                    curr = curr.left
                curr = stack.pop()
                if curr.val <= prev:
                    return False
                prev= curr.val
                curr = curr.right
            return True

Log in to reply

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