Python solution to match '()'\'[]'\'{}'


  • 0
    D
    def isValid(self, s):
            parentheses = []
            for i in s:
                if i in '({[':
                    parentheses.append(i)
                elif i in ')}]':
                    if parentheses:
                        j = parentheses.pop()
                        if j+i not in '() {} []':
                            return False
                    else:
                        return False
            return parentheses == []
    

Log in to reply
 

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