leetcode - 1047. 删除字符串中的所有相邻重复项
题目
代码
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string removeDuplicates(string s) {
string res = "";
int n = s.size();
for(int i = 0; i < n; i++){
if(res.empty() || res.back() != s[i]){
res += s[i];
}else{
res.pop_back();
}
}
return res;
}
int main(){
string s, res;
cin>>s;
res = removeDuplicates(s);
cout<<endl;
cout<<res;
return 0;
}