判断括号是否有效
class Solution:
def isValid(self, s: str) -> bool:
if s=="":
return True
elif s[0]==")" or s[0]=="]" or s[0]=="}":
return False
stack = []
d = {")":"(","]":"[","}":"{"}
for i in s:
if i=="(" or i=="[" or i=="{":
stack.append(i)
else:
if stack==[]:
return False
if stack.pop()!=d[i]:
return False
return stack==[]