题干:

代码:
class Solution {
public:
stack<char> st;
string res = "";
string removeDuplicates(string s) {
for(char i : s){
if(st.empty() || st.top() != i){
st.push(i);
}
else{
st.pop();
}
}
while(!st.empty()){
res += st.top();
st.pop();
}
reverse(res.begin(), res.end());
return res;
}
};
注意:①定义字符串需要将其初始化为空,既“”(就是双引号,中间没括号)。
②一定要判断栈是否为空
③字符串可直接进行字符加减操作
















![(我的创作纪念日)[MySQL]数据库原理7——喵喵期末不挂科](https://img-blog.csdnimg.cn/direct/c88efe5d838e43dd83cc8b8918390a3f.png)


