Last active
July 17, 2021 12:35
-
-
Save walison17/c31938fd0909a73abe9e60929aa95d8b 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 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