class Solution:
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
stack = []
matching = { "(" : ")", "[" : "]", "{" : "}"}
for c in s:
if c in matching.keys():
stack.append(c)
elif c in matching.values():
if len(stack) == 0:
return False
if matching[stack[-1]] != c:
return False
else:
stack.pop()
return len(stack) == 0