✔️ easy & explained solution | C++ | with & without stack STL
Approach without stack STL [explained in code]\n\nThis is a better approach than using stack STL, as the string t used here acts as a stack too.\n\nC++ []\nclas
## Approach without stack STL [explained in code]\n\nThis is a better approach than using stack STL, as the string t used here acts as a stack too.\n\n``` C++ []\nclass Solution {\npublic:\n    string removeDuplicates(string s) {\n        // create another string t\n        string t;\n\n        // let\'s iterate through the string s\n        for (char x:s) {\n            // if the there is nothing in string t we add the current character to t\n            // but if the last character added to string t is same as the current character from string t\n            // we have to remove it\n            if (!t.empty() && t.back()==x) t.pop_back();\n            else t.push_back(x);\n        }\n\n        // and finally we return the string t\n        return t;\n    }\n};\n```\n\n## Approach using stack STL [explained in code]\n\nThis process involves using stack STL and the unnecessary extra steps to put all the characters in stack and then back in string again uses more time.\n\nI\'m putting this up here for the sole sake of your understanding.\n\n``` C++ []\nclass Solution {\npublic:\n    string removeDuplicates(string s) {\n        // create stack st\n        stack<char> st;\n\n        // let\'s iterate through the string s\n        for (char x:s) {\n            // if the there is nothing in stack st we add the current character to st\n            // but if the last character added to stack st is same as the current character from stack st\n            // we have to remove it\n            if (!st.empty() && st.top()==x) st.pop();\n            else st.push(x);\n        }\n\n        // now we\'re going to write s from scratch so clean it up\n        s = "";\n\n        // while stack isn\'t empty let\'s create string s\n        while (!st.empty()) s=st.top()+s, st.pop();\n\n        return s;\n    }\n};\n```
['String', 'Stack', 'C++']