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

  

posted @ 2019-08-16 19:54  尘世中一个迷途小书童  阅读(92)  评论(0编辑  收藏  举报