#include<iostream>
#include<string>
#include<stack>
using namespace std;
class Solution {
public:
string removeDuplicates(string s) {
stack<char> st;
for (char ss:s)
{
if (st.empty() || ss != st.top()) {
st.push(ss);
}
else {
st.pop();
}
}
string result = "";
while (!st.empty()) {
result += st.top();
st.pop();
}
reverse(result.begin(), result.end());
return result;
}
};
栈与队列-删除字符串中的所有相邻重复项
最新推荐文章于 2024-09-14 20:30:05 发布