class Solution:
def removeDuplicates(self, S: str) -> str:
stack = []
for c in S:
if len(stack) == 0 or stack[-1] != c:
stack.append(c)
else:
stack.pop()
return "".join(stack)