栈
class Solution:
def isValid(self, s: str) -> bool:
list_ = list(s)
stack = []
index = None
dict_ = {")":"(","}":"{","]":"[","(":")"}
for i in list_:
if len(stack) != 0:
if i in dict_.keys():
if stack[index] == dict_[i]:
stack.pop()
index-=1
else:
stack.append(i)
index += 1
else:
stack.append(i)
index+=1
else:
stack.append(i)
index = 0
return len(stack)==0