2025-08-02 07:38:33 +0000 UTC

Remove All Adjacent Duplicates In String

Code

class Solution:
    def removeDuplicates(self, s: str) -> str:
        stack = []
        for char in s:
            if stack and char == stack[-1]:
                stack.pop()
            else:
                stack.append(char)
        return "".join(stack)