C++ 5 lines. use string as a stack.
\nclass Solution {\npublic:\n    string removeDuplicates(string S) {\n        string a;\n        for (auto& c : S) \n            if (a.size() && a.back() == c) 
```\nclass Solution {\npublic:\n    string removeDuplicates(string S) {\n        string a;\n        for (auto& c : S) \n            if (a.size() && a.back() == c) a.pop_back();\n            else a.push_back(c);\n        return a;\n    }\n};\n```
[]