C++ 5-line, in-place solution (O(N) time & O(1) space)
We use the given string as a stack.\n\nclass Solution {\npublic:\n    string removeDuplicates(string& s) {\n        int i = 0;\n        for(int j = 1; j < s.siz
We use the given string as a stack.\n```\nclass Solution {\npublic:\n    string removeDuplicates(string& s) {\n        int i = 0;\n        for(int j = 1; j < s.size(); ++j)\n            if (i < 0 || s[i] != s[j]) s[++i] = s[j];\n            else --i;\n        return s.substr(0, i + 1);\n    }\n};\n```
['String', 'Stack', 'C', 'C++']