Created
March 5, 2014 03:24
-
-
Save globby/9360592 to your computer and use it in GitHub Desktop.
Algorithm to check balanced brackets
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 BalancedBrackets(string): | |
a = 0 | |
for x in string: | |
a += 1 if x == '[' else -1 if x == ']' else 0 | |
if a < 0: return False | |
return not a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment