Skip to content

Instantly share code, notes, and snippets.

@tanaydin
Created September 20, 2016 14:49
Show Gist options
  • Save tanaydin/857b3a341b9017e24d9dece76281d29c to your computer and use it in GitHub Desktop.
Save tanaydin/857b3a341b9017e24d9dece76281d29c to your computer and use it in GitHub Desktop.
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