代码:
用栈的思想
class Solution:
def isValid(self, s: str) -> bool:
stack = []
dic = {'(':')','[':']','{':'}'}
for i in s:
if i in dic:
stack.append(i)
else:
if not stack:
return False
else:
if dic[stack[-1]] != i:
return False
else:
stack.pop()
if stack:
return False
else:
return True