classSolution:# @return a booleandefisValid(self,s):ifs=='':returnTrueleft='([{'right=')]}'stack=[]foriins:ifi=='('ori=='['ori=='{':stack.append(i)continueforjinxrange(3):ifi==right[j]:ifnotstackorstack[-1]!=left[j]:returnFalseelse:stack.pop()continuereturnnotstack# tests=Solution()prints.isValid('()')