class Solution {
public:
string removeDuplicates(string S)
{
stack<char> temp;
string s;
for(int i = 0;i < S.size();i++)
{
if(temp.empty())
{
temp.push(S[i]);
}
else
{
if(S[i] == temp.top())
{
temp.pop();
continue;
}
else
{
temp.push(S[i]);
}
}
}
while(!temp.empty())
{
s += temp.top();
temp.pop();
}
if(!s.empty())
reverse(s.begin(),s.end());
return s;
}
};