Skip to content

Latest commit

 

History

History
28 lines (20 loc) · 539 Bytes

1047.Remove-All-Adjacent-Duplicates-In-String.md

File metadata and controls

28 lines (20 loc) · 539 Bytes

1047. Remove All Adjacent Duplicates In String

Difficulty: Easy

URL

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

Solution

Approach 1: Stack

The code is shown below:

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