class Solution:
def isValid(self, s: str) -> bool:
stack = []
paren_map = {')':'(',']':'[','}':'{'}
for c in s:
if c not in paren_map:
stack.append(c)
elif not stack or paren_map[c] != stack.pop():
return False
return not stack
#方法二超出时间限制
def isValid2(self,s: str):
while True:
length = s.__len__()
s=s.replace("()","").replace("{}","").replace("[]","")
if length!=len(s):
break
return s.__le__()==0