[Java/C++/Python] Count Opened Parenthesis
Intuition\nQuote from @shubhama,\nPrimitive string will have equal number of opened and closed parenthesis.\n\n## Explanation:\nopened count the number of opene
## **Intuition**\nQuote from @shubhama,\nPrimitive string will have equal number of opened and closed parenthesis.\n\n## **Explanation**:\n`opened` count the number of opened parenthesis.\nAdd every char to the result,\nunless the first left parenthesis,\nand the last right parenthesis.\n\n## **Time Complexity**:\n`O(N)` Time, `O(N)` space\n\n<br>\n\n**Java:**\n```\n    public String removeOuterParentheses(String S) {\n        StringBuilder s = new StringBuilder();\n        int opened = 0;\n        for (char c : S.toCharArray()) {\n            if (c == \'(\' && opened++ > 0) s.append(c);\n            if (c == \')\' && opened-- > 1) s.append(c);\n        }\n        return s.toString();\n    }\n```\n\n**C++:**\n```\n    string removeOuterParentheses(string S) {\n        string res;\n        int opened = 0;\n        for (char c : S) {\n            if (c == \'(\' && opened++ > 0) res += c;\n            if (c == \')\' && opened-- > 1) res += c;\n        }\n        return res;\n    }\n```\n\n**Python:**\n```\n    def removeOuterParentheses(self, S):\n        res, opened = [], 0\n        for c in S:\n            if c == \'(\' and opened > 0: res.append(c)\n            if c == \')\' and opened > 1: res.append(c)\n            opened += 1 if c == \'(\' else -1\n        return "".join(res)\n```\n
[]