[Python] stack solution, explained
It is given in the statement of the problem that no matter in which order we remove adjacent duplicates in our string, result will always be the same. It is not
It is given in the statement of the problem that no matter in which order we remove adjacent duplicates in our string, result will always be the same. It is not obvious for my why (that is why problem marked as easy, because we can use it), so we we choose the most convinient way for us. Let us go from left to right and try to add element by element. If we see that we have repetition when we add new element, it means that we have adjacent duplicate and we pop element. In the opposite case we add element to stack. In the end we just return what we have in our stack.\n\n#### Complexity\nTime and space complexity is `O(n)`.\n\n#### Code\n```python\nclass Solution:\n    def removeDuplicates(self, s):\n        stack = []\n        for symb in s:\n            if stack and stack[-1] == symb:\n                stack.pop()\n            else:\n                stack.append(symb)\n        return "".join(stack)\n```\n\nIf you have any question, feel free to ask. If you like the explanations, please **Upvote!**
['Stack']