标签:val highlight 判断 ring string append pop tac lse
题目:判断大、中、小括号是否合法。“()”、"([)]"、"{(([])}"
def isValid(string):
dic = {‘}‘:‘{‘,‘]‘:‘[‘,‘)‘:‘(‘}
stack = []
for s in string:
if s not in dic:
stack.append(s)
else:
if len(stack)>0 and dic[s]==stack[-1]:
stack.pop()
else:
return False
return True
标签:val highlight 判断 ring string append pop tac lse
原文地址:https://www.cnblogs.com/kingshine007/p/11366033.html