LeetCode solutions

1128. Remove All Adjacent Duplicates In String

My accepted C++ solution to LeetCode problem 1128, Remove All Adjacent Duplicates In String, running in 0ms.

  • Difficulty: Easy
  • C++
  • Runtime 0ms
  • Memory 13.7MB

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 0ms, memory 13.7MB, accepted 2025-12-27.

cpp
class Solution {
    public:
    string removeDuplicates(string s) {
        string res;
        for (char c : s) {
            if (!res.empty() && res.back() == c) res.pop_back();
            else res.push_back(c);
        }
        return res;
    }
};

Source