注:可以拿字符串直接作为栈
class Solution {
public:
string removeDuplicates(string s) {
string st;
for(int i =0;i<s.length();i++)
{
if(st.empty()||st.back()!=s[i])//当原字符串中的元素与新串最末尾元素不同时,压入字符串
{
st.push_back(s[i]);
}
else{
st.pop_back();//否则相同,就弹出新栈中的末尾元素
}
}
return st;
}
};