# [Leet Code] Remove Outermost Parentheses

`Input: s = "(()())(())"Output: "()()()"Explanation: The input string is "(()())(())", with primitive decomposition "(()())" + "(())".After removing outer parentheses of each part, this is "()()" + "()" = "()()()".`
`Input: s = "(()())(())(()(()))"Output: "()()()()(())"Explanation: The input string is "(()())(())(()(()))", with primitive decomposition "(()())" + "(())" + "(()(()))".After removing outer parentheses of each part, this is "()()" + "()" + "()(())" = "()()()()(())".`
`Input: s = "()()"Output: ""Explanation: The input string is "()()", with primitive decomposition "()" + "()".After removing outer parentheses of each part, this is "" + "" = "".`
`class Solution(object):    def removeOuterParentheses(self, S):        """        :type S: str        :rtype: str        """        stack = []        answer = ""        for i in S:             stack.append(i)            if stack.count("(") == stack.count(")"):                stack.pop()                stack.pop(0)                answer += "".join(stack)                stack = []        return answer`

--

--

--

Learning, and posting my findings!

Love podcasts or audiobooks? Learn on the go with our new app.

## Matthew Boyd

Learning, and posting my findings!