LeetCode20 有效的括号

给定一个只包括 '('')''{''}''['']' 的字符串 s ,判断字符串是否有效。

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

 

posted @ 2021-06-30 22:04  KIKI_FAN  阅读(18)  评论(0编辑  收藏  举报