Skip to content

Commit 8088d9f

Browse files
authored
Create Remove All Adjacent Duplicates In String.cpp
1 parent 31b3451 commit 8088d9f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//1047. Remove All Adjacent Duplicates In String
2+
class Solution {
3+
public:
4+
string removeDuplicates(const string& S) {
5+
string ans;
6+
7+
for (const char c : S)
8+
if (!ans.empty() && ans.back() == c)
9+
ans.pop_back();
10+
else
11+
ans.push_back(c);
12+
13+
return ans;
14+
}
15+
};

0 commit comments

Comments
 (0)