Python 55 ms beats 99.0% using BFS

  • 0
    class Solution(object):
        def isValidBST(self, root):       
            if not root:
                return True        
            q = [[root,-float('inf'),float('inf')]]
            while len(q) != 0:
                top,minRange,MaxRange = q.pop(0)
                if minRange >= top.val or top.val >= MaxRange :
                        return False
                if top.left:
                if top.right:
            return True

Log in to reply

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