class Solution {
public:
stack stk;
string removeDuplicates(string S) {
for(auto x:S)
{
if(stk.size() && stk.top()==x)
{
stk.pop();
}
else stk.push(x);
}
string ans;
while(stk.size())
{
auto t=stk.top();
stk.pop();
ans+=t;
}
return string(ans.rbegin(),ans.rend());
}
};