Concise python solution,beat 99.9%


  • 0
    Y
    class Solution(object):
        def isValidBST(self, root):
            if not root:return True
            stack=[]
            res=[]
            while root or stack:
                if root:
                    stack.append(root)
                    root=root.left
                else:
                    root=stack.pop()
                    res.append(root.val)
                    root=root.right
            if res==sorted(res) and len(res)==len(set(res)):
                return True
            else:return False
    #runtime: 58ms
    #beat 99.90%
    #submit date: Jun 30th ,2017
    

Log in to reply
 

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