一思路 判断左边括号,然后用堆栈法从不能匹配左边括号的元素对应删除,最后判断是否全部匹配 二代码 class Solution(object): def isValid(self, s): """ :type s: str :rtype: bool """ c = ['(','[','{'] a = {")":"(","}":"{","]":"["} b = [0] for i in s: if i in c: b.append(i) elif a[i] == b[-1]: b.pop() else: b.append(i) return b == [0]