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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 13.7MB, accepted 2025-12-27.
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;
}
};