✅☑️ Best C++ 2 Solution Ever || String || Stack || One Stop Solution.
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can solve this question using Multiple Approaches. (Here I have explained all the po
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can solve this question using Multiple Approaches. (Here I have explained all the possible solutions of this problem).\n\n1. Solved using String + Stack.\n2. Solved using String.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can easily understand the all the approaches by seeing the code which is easy to understand with comments.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nTime complexity is given in code comment.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nSpace complexity is given in code comment.\n\n# Code\n```\n/*\n\n    Time Complexity : O(N), Where N is the size of the string(num). Here loop creates the time complexity.\n\n    Space complexity : O(N), Stack(store) space.\n\n    Solved using String + Stack.\n\n*/\n\n\n/***************************************** Approach 1 *****************************************/\n\nclass Solution {\npublic:\n    string removeOuterParentheses(string s) {\n        stack<char> store;\n        string ans = "";\n        for(auto c : s){\n            if(c == \'(\'){\n                if(store.size() > 0){\n                    ans += c;\n                }\n                store.push(c);\n            }\n            else if(c == \')\'){\n                if(store.size() > 1){\n                    ans += c;\n                }\n                store.pop();\n            }\n        }\n        return ans;\n    }\n};\n\n\n\n\n\n\n/*\n\n    Time Complexity : O(N), Where N is the size of the string(num). Here loop creates the time complexity.\n\n    Space complexity : O(1), Constant space. Extra space is only allocated for the String(ans), however the\n    output does not count towards the space complexity.\n\n    Solved using String.\n\n*/\n\n\n/***************************************** Approach 2 *****************************************/\n\nclass Solution {\npublic:\n    string removeOuterParentheses(string s) {\n        string ans = "";\n        int openParentheses = 0;\n        for(auto c : s){\n            if(c == \'(\'){\n                if(openParentheses > 0){\n                    ans += c;\n                }\n                openParentheses++;\n            }\n            else if(c == \')\'){\n                if(openParentheses > 1){\n                    ans += c;\n                }\n                openParentheses--;\n            }\n        }\n        return ans;\n    }\n};\n\n```\n\n***IF YOU LIKE THE SOLUTION THEN PLEASE UPVOTE MY SOLUTION BECAUSE IT GIVES ME MOTIVATION TO REGULARLY POST THE SOLUTION.***\n\n![WhatsApp Image 2023-02-10 at 19.01.02.jpeg](https://assets.leetcode.com/users/images/0a95fea4-64f4-4502-82aa-41db6d77c05c_1676054939.8270252.jpeg)
['String', 'Stack', 'C++']