Counter를 알게된 순간... collections 에 어떤게 있는지 알아보는 계기가 되었다. class Solution: def removeDuplicateLetters(self, s: str) -> str: counter, result, stack = collections.Counter(s), set(), [] for c in s: counter[c] -= 1 if c in result: continue while stack and c 0: result.remove(stack.pop()) stack.append(c) result.add(c) return ''.join(stack) https://leetcode.com/problems..