Skip to content

Commit 8b74a10

Browse files
authored
Create remove-all-adjacent-duplicates-in-string.py
1 parent 6eae3cf commit 8b74a10

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
class Solution(object):
5+
def removeDuplicates(self, S):
6+
"""
7+
:type S: str
8+
:rtype: str
9+
"""
10+
result = []
11+
for c in S:
12+
if result and result[-1] == c:
13+
result.pop()
14+
else:
15+
result.append(c)
16+
return "".join(result)

0 commit comments

Comments
 (0)