题解 | #有效括号序列#
有效括号序列
https://www.nowcoder.com/practice/37548e94a270412c8b9fb85643c8ccc2
class Solution: def isValid(self , s: str) -> bool: # write code here def pair(char): if char == '}': return '{' elif char == ']': return '[' elif char == ')': return '(' stack = [] for x in s: if pair(x) in stack: stack.pop() else: stack.append(x) return not stack