C++ Three Simple Solutions || with and without stack
Code 1 : with stack\n# Complexity\n- Time complexity: O(N) Traverse each char from string\n- Space complexity: O(N) Using stack \n\nclass Solution {\npublic:\n 
# Code 1 : with stack\n# Complexity\n- Time complexity: O(N) Traverse each char from string\n- Space complexity: O(N) Using stack \n```\nclass Solution {\npublic:\n    string removeDuplicates(string s) {\n        string ans="";\n        stack<char> st;\n\n        for(char i: s){\n            if(st.empty() or i != st.top()) st.push(i);\n\n            else\n                st.pop();\n        }\n\n        while(!st.empty()){\n            ans+= st.top();\n            st.pop();\n        }\n\n        reverse(ans.begin(), ans.end());\n        return ans;\n    }\n};\n```\n\n# Code 2 : without stack\n# Complexity\n- Time complexity: O(N) Traverse each char from string\n- Space complexity: O(1) \n```\nclass Solution {\npublic:\n    string removeDuplicates(string s) {\n        string ans="";\n        \n        for(int i=0; i<s.length(); i++){\n            if(s[i]==0 or ans.back() != s[i]) \n                ans+= s[i];\n\n            else if(ans.back()==s[i]) \n                ans.pop_back();\n        }\n\n        return ans;\n    }\n};\n```\n\n# Code 3 : without stack\n\n# Complexity\n- Time complexity: O(N*N) Traverse each char from string\n             extra O(N) because of erase function.\n- Space complexity: O(1) \n```\nclass Solution {\npublic:\n    string removeDuplicates(string s) {\n        int i=0;\n        int n= s.size();\n\n        while(i<n){\n            if(s[i]==s[i+1]){\n                s.erase(s.begin()+i); \n                s.erase(s.begin()+i);\n\n                if(i>0) i--;\n\n                n= s.size();\n            }\n\n            else i++;\n        }      \n\n        return s;\n    }\n};\n```
['String', 'Stack', 'C++']