IT/Computer Science
[Leetcode/Stack] 1047. Remove All Adjacent Duplicates In String
Diana Kang
2025. 6. 11. 22:17
https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/
class Solution:
def removeDuplicates(self, s: str) -> str:
stack = []
for c in s:
if stack and stack[-1] == c:
stack.pop()
else:
stack.append(c)
return ''.join(stack)