1047. Remove All Adjacent Duplicates In String
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 71% Topics: String, Stack
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(n)
class Solution(object):
def removeDuplicates(self, S):
"""
:type S: str
:rtype: str
"""
result = []
for c in S:
if result and result[-1] == c:
result.pop()
else:
result.append(c)
return "".join(result)
Solution from kamyu104/LeetCode-Solutions · MIT