✅ [Python/C++/Java/Rust] Make The Stack Great Again (explained)
\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.\n*\nThis solution employs a stack to keep track of equal adjacent letters. Time complexity is linear: *O(N). Sp
**\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n****\nThis solution employs a stack to keep track of equal adjacent letters. Time complexity is linear: **O(N)**. Space complexity is linear: **O(N)**.\n\n**Comment.** To remove adjacent duplicates, we iteratively compare each letter with the last letter on the stack. This problem is almost identical to the November 8th\'s daily challenge [**1544. Make The String Great**](https://leetcode.com/problems/make-the-string-great/) (check my [**solution**](https://leetcode.com/problems/make-the-string-great/discuss/2790965/PythonC%2B%2BJavaRust-Make-The-String-Great-Again-(explained))).\n\n**Python.**\n```\nclass Solution:\n    def removeDuplicates(self, s: str) -> str:\n        ss = []\n        for c in s:\n            if ss and ss[-1] == c : ss.pop()\n            else                  : ss.append(c)\n        return "".join(ss)\n```\n\nThis solution in other languages.\n\n<iframe src="https://leetcode.com/playground/dekDhVK9/shared" frameBorder="0" width="800" height="320"></iframe>
[]