Skip to content

Instantly share code, notes, and snippets.

@seanballais
Created April 15, 2018 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanballais/a1163dcd4d64d2e45a52b54f8e01b0f2 to your computer and use it in GitHub Desktop.
Save seanballais/a1163dcd4d64d2e45a52b54f8e01b0f2 to your computer and use it in GitHub Desktop.
def pair_balance(parentheses):
missing_pairs = 0
for parenthesis in parentheses:
if parenthesis == '(':
missing_pairs += 1
elif parenthesis == ')':
if missing_pairs == 0:
return False
missing_pairs -= 1
return True if missing_pairs == 0 else False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment