Last active
February 23, 2017 06:03
-
-
Save DavidPu/ad163a183896e969b6c929b4ed4642a5 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
def check_string(s): | |
mstack = [] | |
bFind = False | |
matches = {')': '(', '}': '{', ']': '['} | |
for c in s: | |
if c in matches.values(): | |
bFind = True | |
mstack.append(c) | |
elif c in matches.keys(): | |
if len(mstack) == 0 or mstack[-1] != matches[c]: | |
return False | |
mstack.pop() | |
else: | |
print("unexpected character") | |
return False | |
return bFind and len(mstack) == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment