括号匹配
def isValid(s):
"""
:type s: str
:rtype: bool
"""
stack = []
ftype1 = '('
ftype2 = '['
ftype3 = '{'
btype1 = ')'
btype2 = ']'
btype3 = '}'
for ele in s:
if ele in '([{':
stack.append(ele)
elif ele in ')]}':
if not stack:
return False
if stack:
if ele == btype1 and stack[-1] == ftype1 or ele == btype2 and stack[-1] == ftype2 or ele == btype3 and \
stack[-1] == ftype3:
stack.pop()
else:
return False
if not stack:
return True
else:
return False