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

  

上一篇:springboot druid数据库密码加密


下一篇:F - Parentheses