Easy
Remove All Adjacent Duplicates In String — Python
Full explanation · Time O(n) · Space O(n)
# Time: O(n)
# Space: O(n)
class Solution(object):
def removeDuplicates(self, S):
"""
:type S: str
:rtype: str
"""
result = []
for c in S:
if result and result[-1] == c:
result.pop()
else:
result.append(c)
return "".join(result)