Python Inorder Solution with stack.[BEAT 82%]


  • 0
    L
    class Solution(object):
        def isValidBST(self, root):
            """
            :type root: TreeNode
            :rtype: bool
            """
            stack = []
            curr = root
            prev = -0xFFFFFFFF
            while curr or stack:
                while curr:
                    stack.append(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.