20-Valid Parentheses
题目:判断大、中、小括号是否合法。“()”、"([)]"、"{(([])}"
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

浙公网安备 33010602011771号