Why there is a compile error on my code


  • 0
    D
    class Solution:
    # @return a boolean
    def isValid(self, s):
        open=set("([{")
        match=set([ ('(',')'), ('[',']'), ('{','}') ])
        stack=[]
        for char in s: 
            if char in open: 
                stack.append(char) 
            else: 
                if len(stack)==0: 
                    return False 
                lastOpen=stack.pop() 
                if (lastOpen, char) not in match:
                    return False
        return len(stack)==0

Log in to reply
 

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