C++ 2 solutions. Easy to understand.
Solution using stack.\n(Scroll down for more optimized solution.)\n\nclass Solution {\npublic:\n    string removeDuplicates(string s) \n    {\n        stack<cha
* **Solution using stack.**\n(Scroll down for more optimized solution.)\n```\nclass Solution {\npublic:\n    string removeDuplicates(string s) \n    {\n        stack<char>st;\n        string ans;\n        for(int i=0;i<s.size();i++)\n        {\n            if(st.size() == 0)\n            {\n                st.push(s[i]);\n            }\n            else if(s[i] == st.top())\n            {\n                st.pop();\n            }\n            else\n            {\n                st.push(s[i]);\n            }\n        }\n        while(st.size() != 0)\n        {\n            ans += st.top();\n            st.pop();\n        }\n        reverse(ans.begin(),ans.end());\n        return ans;\n    }\n};\n```\n* **More optimized solution (faster than 96.15%)**\n```\nclass Solution {\npublic:\n    string removeDuplicates(string s) \n    {\n        string ans;\n        ans.push_back(s[0]);\n        for(int i=1;i<s.size();i++)\n        {\n            if(s[i] == ans.back())\n            {\n                ans.pop_back();\n            }\n            else\n            {\n                ans.push_back(s[i]);\n            }\n        }\n        return ans;\n    }\n};\n```\n**Like the solution?\nPlease upvote \u30C4**
['Stack', 'C', 'C++']