1047. Remove All Adjacent Duplicates In String

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1047

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