C++ Easy | Detailed Explanation
\u2705 PLEASE UPVOTE IF YOU LIKE! \u2705\n\n\nclass Solution {\npublic:\n    string removeDuplicates(string s) {\n        \n        string ans;\n        \n     
**\u2705 PLEASE UPVOTE IF YOU LIKE! \u2705**\n\n```\nclass Solution {\npublic:\n    string removeDuplicates(string s) {\n        \n        string ans;\n        \n        for(int i = 0 ; i < s.size() ; i++)\n        {\n            if(ans.size() && ans.back() == s[i])\n                ans.pop_back();\n            else\n                ans.push_back(s[i]);\n        }\n        \n        return ans;\n    }\n};\n```\n**TC : 0(n)**           **SC : O(n)**\n\n**Explanation :**\n\n\t\t\t\t\t\ts = "abbaca"\n\t\t\t\t\t\t\n1. \t\t\t\t\t\tans = a              s[i+1] = b\n1. \t\t\t\t\t\tans = ab             s[i+1] = b\n1. \t\t\t\t\t\tans = a              s[i+1] = a\n1. \t\t\t\t\t\tans = c              s[i+1] = a\n1. \t\t\t\t\t\tans = ca      \n\t\t\t\t\t\t \n \t\t\t\t\t\tFinally ans = "ca"        \n
['C']