1
class Solution {
2
public:
3
stack<char> st;
4
string removeDuplicates(string s) {
5
string ans;
6
char c;
7
for (auto &i : s) {
8
if (st.empty()) {
9
st.push(i);
10
continue;
11
}
12
if (i == st.top())
13
st.pop();
14
else
15
st.push(i);
16
}
17
while (!st.empty()) {
18
c = st.top();
19
ans += c;
20
st.pop();
21
}
22
reverse(begin(ans), end(ans));
23
return ans;
24
}
25
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0