Well Explained Code in JAVA ||
\n\n# Approach\nThis is a solution to the problem of removing outermost parentheses from a string containing only parentheses.\n\nThe approach used is to keep t
\n\n# Approach\nThis is a solution to the problem of removing outermost parentheses from a string containing only parentheses.\n\nThe approach used is to keep track of the parentheses using a stack. Whenever an opening parenthesis is encountered, it is pushed onto the stack. Whenever a closing parenthesis is encountered, the last opening parenthesis is popped from the stack.\n\nIf the stack size is greater than zero after pushing or popping, it means that the parenthesis is not an outer parenthesis, and it is added to the result string. If the stack size is zero, it means that the parenthesis is an outer parenthesis and it is not added to the result string.\n\n# Complexity\n- Time complexity:\nThe time complexity of this solution is O(n), where n is the length of the input string. This is because each character in the string is processed once and the push and pop operations on the stack take O(1) time each.\n\n\n\n- Space complexity:\nThe space complexity of this solution is O(n), where n is the length of the input string. This is because the maximum size of the stack is n/2 (if all the parentheses are opening parentheses), and in the worst case, the result string can also have a size of n/2.\n\n# Code\n```\nclass Solution {\n    public String removeOuterParentheses(String s) {\n        Stack<Character> bracket = new Stack<>();\n        StringBuilder sb = new StringBuilder("");\n        for(int i=0;i<s.length();i++){\n            if(s.charAt(i)==\'(\'){\n                if(bracket.size()>0){\n                    sb.append(s.charAt(i));\n                }\n                bracket.push(s.charAt(i));\n            }else{\n                bracket.pop();\n                if(bracket.size()>0){\n                    sb.append(s.charAt(i));\n                }\n            }\n        }\n        return sb.toString();\n    }\n}\n```\n![upvote.jpeg](https://assets.leetcode.com/users/images/150a5515-b27f-42d1-9a2e-aed10f236bca_1675969899.9073486.jpeg)\n
['Stack', 'Java']