ByteByteGo: Repeated Removal of Adjacent Duplicates
β’ 35 words β’ 1 min β’ updated
ByteByteGo: Repeated Removal of Adjacent Duplicates:
python
def repeated_removal_of_adjacent_duplicates(s: str) -> str:
stack = []
for c in s:
if len(stack) == 0 or stack[-1] != c:
stack.append(c)
elif stack[-1] == c:
stack.pop()
return ''.join(stack)