#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param s string字符串
# @return bool布尔型
#
class Solution:
def isValid(self, s: str) -> bool:
# write code here
stack = []
for c in s:
if c == ")":#小括号匹配
if len(stack) > 0 and stack[-1] == "(":
stack.pop()
else:
return False
elif c == "]":#中括号匹配
if len(stack) > 0 and stack[-1] == "[":
stack.pop()
else:
return False
elif c == "}":#大括号匹配
if len(stack) > 0 and stack[-1] == "{":
stack.pop()
else:
return False
else:#正括号入栈
stack += c
return True if len(stack)==0 else False#判断是否完全匹配完