Created
March 25, 2020 03:51
-
-
Save BharathKumarS/2cee97e973a79efc8b8b7109577b8190 to your computer and use it in GitHub Desktop.
LeetCode, Remove outermost parentheses
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
class Solution: | |
def removeOuterParentheses(self, S): | |
result = '' | |
openB = closeB = start = 0 | |
for bracket in range(len(S)): | |
if S[bracket] == '(': | |
openB += 1 | |
else: | |
closeB += 1 | |
if openB == closeB: | |
end = bracket | |
if S[start:end] != '()': | |
result = result + (S[start+1:end]) | |
openB = closeB = end = 0 | |
start = bracket + 1 | |
return(result) | |
if __name__ == '__main__': | |
S = "()()()()" | |
brackets = Solution() | |
result = brackets.removeOuterParentheses(S) | |
print(result) |
Author
BharathKumarS
commented
Mar 25, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment