c++ | without stack
\nclass Solution {\npublic:\n    string minRemoveToMakeValid(string s){\n        int cnt=0;\n        for(char &c: s){\n            if(c==\'(\') cnt++;\n        
```\nclass Solution {\npublic:\n    string minRemoveToMakeValid(string s){\n        int cnt=0;\n        for(char &c: s){\n            if(c==\'(\') cnt++;\n            else if(c==\')\')\n                if(cnt==0) c=\'*\';\n                else cnt--;\n        }\n        cnt=0;\n        for(int i=s.size()-1;i>=0;i--){\n            if(s[i]==\')\') cnt++;\n            else if(s[i]==\'(\')\n                if(cnt==0) s[i]=\'*\';\n                else cnt--;\n        }\n        s.erase(remove(s.begin(),s.end(),\'*\'),s.end());\n        return s;\n    }\n};\n```\n**Feel free to ask any question in the comment section.**\nI hope that you\'ve found the solution useful.\nIn that case, **please do upvote and encourage me** to on my quest to document all leetcode problems\uD83D\uDE03\nHappy Coding :)\n
['C', 'C++']