Last active
August 29, 2019 10:28
-
-
Save spy16/12614bb5c089f1d9b40ef82eff482922 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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