题目:
题解:
class Solution:def removeDuplicateLetters(self, s: str) -> str:vis = defaultdict(int)cnt = defaultdict(int)for ch in s: cnt[ch] += 1queue = []for ch in s:if vis[ch] == 0:while queue and queue[-1] > ch and cnt[queue[-1]]:vis[queue.pop()] = 0if not queue or queue != ch: queue.append(ch)vis[ch] = 1cnt[ch] -= 1return "".join(queue)