题解 | #括号序列#
括号序列
http://www.nowcoder.com/practice/37548e94a270412c8b9fb85643c8ccc2
```# # # @param s string字符串 # @return bool布尔型 # import collections class Solution: def isValid(self , s ): # write code here brackets = [i for i in s] n = len(brackets) if n==0 or n%2 == 1: return False stack = [] match = {"(":")", "[":"]", "{":"}"} left = match.keys() right = match.values() for n in s: if n in left: stack.append(n) elif n in right: if not stack: return False curr = stack.pop() if curr in left: if match[curr]!=n: return False else: return False if stack: return False else: return True