C++ || faster than 90% || stack || easy-to-understand ||
Intuition\n Describe your first thoughts on how to solve this problem. \nAs its clearly mentioned the adjacent were to delete and if we delete any middle sequen
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs its clearly mentioned the adjacent were to delete and if we delete any middle sequence it might be possible for the case to give another sequesnce consisting of first element so, stack was the best possible data structure I could think about.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst -- pushing the first element inti the stack,\nsecondly-- checking if the upcomming elemnt is equal to the top of the stack if true pop() the top and move forwrd.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\no(n)\nP.S : there is no need of the while loop you can ommit it and just pop() the top element. \n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\no(n)\n\n# Code\n```\nclass Solution {\npublic:\n    string removeDuplicates(string s) {\n        stack<char> stk;\n        string ans;\n        for(auto&i: s){\n            if(stk.empty())\n            {\n                stk.push(i);\n            }\n            else{\n                if(i==stk.top())\n                {\n                    while(!stk.empty() && stk.top()==i)\n                    {\n                        stk.pop();\n                    }\n                }\n                else{\n                    stk.push(i);\n                    }\n            }\n        }\n        while(!stk.empty())\n        {\n            ans.push_back(stk.top());\n            stk.pop();\n        }\n        reverse(ans.begin(),ans.end());\n        return ans;\n    }\n        \n};\n```
['String', 'Stack', 'C++']