C++ 1 line & 4 lines, O(n) time
Update: the 1 line version no longer work in C++ 20.\n\nBuild the result string in a stack way. 1 line version:\ncpp []\nstring removeDuplicates(string S) {\n  
Update: the 1 line version no longer work in C++ 20.\n\nBuild the result string in a stack way. 1 line version:\n```cpp []\nstring removeDuplicates(string S) {\n    return accumulate(S.begin(), S.end(), string(), [](auto &s, char c)->auto& {return s.size() && s.back() == c ? s.pop_back() : s.push_back(c), s;});\n}\n```\n4 line version:\n```cpp []\nstring removeDuplicates(string S) {\n    string s;\n    for (char c : S)\n        s.size() && s.back() == c ? s.pop_back() : s.push_back(c);\n    return s;\n}\n```
['C++']