Skip to content

Instantly share code, notes, and snippets.

@spy16
Last active August 29, 2019 10:28
Show Gist options
  • Save spy16/12614bb5c089f1d9b40ef82eff482922 to your computer and use it in GitHub Desktop.
Save spy16/12614bb5c089f1d9b40ef82eff482922 to your computer and use it in GitHub Desktop.
opposites = {
")": "(",
"]": "[",
"}": "{",
}
def check(s):
stack = []
for c in s:
if c in ")}]":
if stack.pop() != opposites[c]:
return False
else:
stack.append(c)
return len(stack) == 0
def braces(values):
res = []
for x in values:
if check(x):
res.append("yes")
else:
res.append("no")
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment