20. 有效的括号
20. 有效的括号
方法一
class Solution(object): def isValid(self, s): """ :type s: str :rtype: bool """ d = {'}': '{', ']': '[', ')': '('} stack = [] for c in s: if c not in d: stack.append(c) continue if not stack or stack.pop() != d[c]: return False return False if stack else True