class Solution: def isValid(self, s: str) -> bool: stack = [] m = { ')': '(', '}': '{', ']': '[' } for c in s: if c in ['(', '{', '[']: stack.append(c) elif len(stack) == 0 or c in [')', '}', ']'] and stack[-1] != m[c]: return False else: stack.pop() return len(stack) == 0