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
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
转载于:https://www.cnblogs.com/songxiaohua/p/9826991.html