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