Created
September 1, 2014 12:28
-
-
Save bluven/3225d64e2c2d21cdd576 to your computer and use it in GitHub Desktop.
check if a string is parentheses balanced
This file contains 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 is_parentheses_balanced(expression): | |
stack = [] | |
for symbol in expression: | |
if symbol == '(': | |
stack.append(symbol) | |
if symbol == ')': | |
if (not stack) or stack.pop(-1) != '(': | |
return False | |
if stack: | |
return False | |
return True | |
print is_parentheses_balanced('((())())()') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment