Python stack
\n# C \u2B55 D E \u262F\nclass Solution:\n    def removeDuplicateLetters(self, s: str) -> str:\n        d = Counter(s)\n        visited = set()\n        stack =
```\n# C \u2B55 D E \u262F\nclass Solution:\n    def removeDuplicateLetters(self, s: str) -> str:\n        d = Counter(s)\n        visited = set()\n        stack = []\n        for i in range(len(s)):\n            d[s[i]] -= 1\n            if s[i] not in visited:\n                while stack and stack[-1] > s[i] and d[stack[-1]]:\n                    # stack.pop()\n                    visited.remove(stack[-1])\n                    stack.pop()\n                visited.add(s[i])\n                stack.append(s[i])\n            \n        return "".join(stack)\n    \n            \n```
['Stack', 'Python', 'Python3']