1047. Remove All Adjacent Duplicates In String
stackで貯めていき、stackのtopと同じ文字がきたら、popする。
'''cpp
class Solution {
public:
string removeDuplicates(string s) {
stack
for(char i:s)
{
if(st.size() == 0)
{
st.push(i);
}
else if(i == st.top())
{
st.pop();
}
else
{
st.push(i);
}
}
string ans;
while(st.size() != 0)
{
ans += st.top();
st.pop();
}
reverse(ans.begin(),ans.end());
return ans;
}
}; '''