添加 1047.删除字符串中的所有相邻重复项

This commit is contained in:
pppig
2021-05-18 14:32:32 +08:00
committed by GitHub
parent 632ec4bdd4
commit 6079bfa439

View File

@ -146,7 +146,17 @@ class Solution {
```
Python
```python3
class Solution:
def removeDuplicates(self, s: str) -> str:
t = list()
for i in s:
if t and t[-1] == i:
t.pop(-1)
else:
t.append(i)
return "".join(t) # 字符串拼接
```
Go