Easy and Simple C++ solution | Beats 100% 🔥🔥
Problem Explanation\n\nThe problem is to remove adjacent duplicate characters in a string until no more adjacent duplicates are left. For example, given the str
# Problem Explanation\n\nThe problem is to remove adjacent duplicate characters in a string until no more adjacent duplicates are left. For example, given the string `"abbaca"`, the result should be `"ca"` after removing adjacent duplicates.\n\n# Approach\n\n1) **Initialize an empty string `temp`:**\n\n    - This string acts as a temporary storage to keep track of characters while processing the input string `s`.\n\n2) **Iterate through the input string `s`:**\n\n    - Use a `while` loop to go through each character in the string `s`.\n\n3) **Check conditions inside the loop:**\n\n    - If `temp` is empty or the current character `s[i]` is not the same as the last character in `temp` (`temp.back()`), add the current character to `temp`.\n    - If `s[i]` is the same as `temp.back()`, it means we have found an adjacent duplicate. Remove the last character from `temp` by using `temp.pop_back()`.\n\n4) **Return `temp`:**\n\n    - After processing all characters, `temp` will contain the resulting string with no adjacent duplicates.\n\n# Reason for Using This Approach\n\n- **Using a String for Temporary Storage:**\n\n    - The string `temp` is used to simulate the behavior of a stack. This is a convenient way to handle the problem of adjacent duplicates because it allows easy addition and removal of characters from the end of the string.\n\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n`Upvote! It only takes 1 click\uD83D\uDE09`\n# Code\n```\nclass Solution {\npublic:\n    string removeDuplicates(string s) {\n        string temp = "";\n        int i = 0;\n        \n        while (i < s.length()) {\n            if (temp.empty() || s[i] != temp.back()) {\n                temp.push_back(s[i]);\n            } else {\n                temp.pop_back();\n            }\n            i++;\n        }\n        \n        return temp;\n    }\n};\n```\n![upvote.jpeg](https://assets.leetcode.com/users/images/48b755ae-c41b-474d-966e-aa5674e41ff4_1720943081.9620614.jpeg)
['String', 'Stack', 'C++']