Created
September 20, 2016 14:49
-
-
Save tanaydin/857b3a341b9017e24d9dece76281d29c to your computer and use it in GitHub Desktop.
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_balanced(s): | |
p = [] | |
for l in s: | |
if l == '(': | |
p.append(l) | |
elif l == ')': | |
if not p: | |
return False | |
else: | |
p.pop() | |
if not p: | |
return True | |
return False | |
print "T" | |
print is_balanced('(()()()())') | |
print is_balanced('(((())))') | |
print is_balanced('(()((())()))') | |
print "F" | |
print is_balanced('((((((())') | |
print is_balanced('()))') | |
print is_balanced('(()()(())') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment