题解 | #有效括号序列#
有效括号序列
https://www.nowcoder.com/practice/37548e94a270412c8b9fb85643c8ccc2
class Solution:
def isValid(self , s: str) -> bool:
# write code here
dic={'(':')','[':']','{':'}'}
list1=[]
for i in s:
if i in '({[':
list1.append(dic[i])
elif len(list1)==0:
return False
elif list1[-1]==i:
list1.pop()
return len(list1)==0