LeetCodeDiary

A Diary for solving LeetCode problems

View on GitHub
'''
Description: 
Autor: Au3C2
Date: 2021-03-09 10:51:36
LastEditors: Au3C2
LastEditTime: 2021-03-09 10:51:54
'''
class Solution:
    def removeDuplicates(self, S: str) -> str:
        ans = list()
        for c in S:
            if ans and ans[-1] == c:
                ans.pop()
            else:
                ans.append(c)
        return ''.join(ans)
    
# 栈,简单
# https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/