Leetcode 1128 Solution

This article provides solution to leetcode question 1128 (remove-all-adjacent-duplicates-in-string)

https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string

Solution

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