class Solution:
def isValid(self, s: str) -> bool:
brackets = []
mapping = {")": "(", "}": "{", "]": "["}
for c in s:
if c in mapping:
last_bracket = brackets.pop() if brackets else 'EMPTY'
if mapping[c] != last_bracket:
return False
else:
brackets.append(c)
return not brackets
O(N)
O(N)