9-line Simple C++ Solution No Stack No Deque!!!
Please upvote if you find the code helpful!!!\nThis solution is sort of a simili to a stack, but I am not using stack here.\n\n// Without explanation -- for tho
Please ***upvote*** if you find the code helpful!!!\nThis solution is sort of a simili to a stack, but I am not using stack here.\n```\n// Without explanation -- for those who want to copy-paste my solution ;)\nclass Solution {\npublic:\n    string minRemoveToMakeValid(string s) {\n        int C = 0; string ans; vector<char> hehe;\n        for (int i = 0; i < s.size(); i++) {\n            if (s[i] == \'(\') { C++; hehe.push_back(s[i]); } \n            else if (s[i] == \')\') {if (C > 0) { C--; hehe.push_back(s[i]); }}\n            else hehe.push_back(s[i]); \n        }\n        if (C > 0) for (int i = hehe.size() - 1; i >= 0; i--) if (hehe[i] == \'(\') { hehe.erase(hehe.begin() + i); C--; if (C == 0) break; }\n        for (int i = 0; i < hehe.size(); i++) ans += hehe[i];\n        return ans;\n    }\n};\n```\n```\n// With explanation\nclass Solution {\npublic:\n    string minRemoveToMakeValid(string s) {\n\t\t// Defining the variables\n        int C = 0; string ans; vector<char> hehe;\n        for (int i = 0; i < s.size(); i++) {\n\t\t\t // add a \'(\' every time we encounter one\n            if (s[i] == \'(\') { C++; hehe.push_back(s[i]); }\n\t\t\t// make sure that the number of \'(\' is equal to the number of \')\'; if there are more \')\' than \'(\', skip\n            else if (s[i] == \')\') {if (C > 0) { C--; hehe.push_back(s[i]); }}\n            // if char is a lowercase letter just add the letter\n\t\t\telse hehe.push_back(s[i]);\n        }\n\t\t// If there are more \'(\' than \')\' at the end, delete the \'(\' from right to left\n\t\t// until when the number of \'(\' is equal to the number of \')\' (i.e. when C == 0)\n        if (C > 0) for (int i = hehe.size() - 1; i >= 0; i--) if (hehe[i] == \'(\') { hehe.erase(hehe.begin() + i); C--; if (C == 0) break; }\n\t\t// Add the remaining chars in the answer since we need to return a string\n        for (int i = 0; i < hehe.size(); i++) ans += hehe[i];\n\t\t// Return da answer!\n        return ans;\n    }\n};\n```\n```\n// Readable Version With explanation\nclass Solution {\npublic:\n    string minRemoveToMakeValid(string s) {\n\t\t// Defining the variables\n        int C = 0;\n        string ans;\n        vector<char> hehe;\n        for (int i = 0; i < s.size(); i++) {\n\t\t\t// add a \'(\' every time we encounter one\n            if (s[i] == \'(\') {\n                C++;\n                hehe.push_back(s[i]);\n            }\n\t\t\t// make sure that the number of \'(\' is equal to the number of \')\'; if there are more \')\' than \'(\', skip\n            else if (s[i] == \')\') {\n                if (C > 0) {\n                    C--;\n                    hehe.push_back(s[i]);\n                }\n            }\n\t\t\t// if char is a lowercase letter just add the letter\n            else hehe.push_back(s[i]);\n        }\n\t\t// If there are more \'(\' than \')\' at the end, delete the \'(\' from right to left\n\t\t// until when the number of \'(\' is equal to the number of \')\' (i.e. when C == 0)\n        if (C > 0) {\n            for (int i = hehe.size() - 1; i >= 0; i--) {\n                if (hehe[i] == \'(\') {\n                    hehe.erase(hehe.begin() + i); C--;\n                    if (C == 0) break;\n                }\n            }\n        }\n\t\t// Add the remaining chars in the answer since we need to return a string\n        for (int i = 0; i < hehe.size(); i++) ans += hehe[i];\n\t\t// Return da answer!\n        return ans;\n    }\n};\n```\nPlease ***upvote*** if you find the code helpful!!!
['C', 'C++']