数据结构之栈实现检查左右括号是否匹配

def isValid(self,s):
    stack = []
    paren_map = {')': '(', ']': '[', '}': '{'}
    for c in s:
        if c not in paren_map:
            stack.append(c)
        elif not stack or paren_map[c] != stack.pop():
            return False
     return not stack

 

posted @ 2018-10-21 21:26  PLAY_JOY  阅读(358)  评论(0编辑  收藏  举报