Python括号序列-代码优化
括号序列
http://www.nowcoder.com/questionTerminal/37548e94a270412c8b9fb85643c8ccc2
用字典简化代码量
class Solution: def isValid(self , s ): k = {'}':'{', ')':'(', ']':'[' } stack = [] for a in s: if a in k.values(): stack.append(a) elif not stack or k[a] != stack.pop(): return False return len(stack) == 0