1 class Solution: 2 def removeDuplicates(self, S: str) -> str: 3 l = [] 4 for i in range(len(S)): 5 s = S[i] 6 if len(l) == 0: 7 l.append(s) 8 else: 9 top = l[-1] 10 if s == top: 11 l.pop(-1) 12 else: 13 l.append(s) 14 result = '' 15 for i in range(len(l)): 16 result += l[i] 17 return result