Skip to content

Commit 6eae3cf

Browse files
authored
Create remove-all-adjacent-duplicates-in-string.cpp
1 parent 94c9d86 commit 6eae3cf

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Time: O(n)
2+
// Space: O(n)
3+
4+
class Solution {
5+
public:
6+
string removeDuplicates(string S) {
7+
string result;
8+
for (const auto& c : S) {
9+
if (!result.empty() && result.back() == c) {
10+
result.pop_back();
11+
} else {
12+
result.push_back(c);
13+
}
14+
}
15+
return result;
16+
}
17+
};

0 commit comments

Comments
 (0)