Skip to content

Instantly share code, notes, and snippets.

@walison17
Last active July 17, 2021 12:35
Show Gist options
  • Save walison17/c31938fd0909a73abe9e60929aa95d8b to your computer and use it in GitHub Desktop.
Save walison17/c31938fd0909a73abe9e60929aa95d8b to your computer and use it in GitHub Desktop.
def remove_brackets(text):
"""
>>> remove_brackets('(())()(((')
3
>>> remove_brackets('(()(')
2
>>> remove_brackets('()')
0
"""
x = 0
for t in text:
if t == '(':
x += 1
elif t == ')':
x -= 1
return max(x, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment