题解 | #删除字符串中出现次数最少的字符# 队列 + 哈希
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
from collections import deque, defaultdict import sys for line in sys.stdin: s = line.strip() q = deque() counter = defaultdict(int) for c in s: q.append(c) counter[c] += 1 del_set = set() mini_cnt = len(s) for key in counter.keys(): mini_cnt = min(mini_cnt, counter[key]) for key in counter.keys(): if counter[key] == mini_cnt: del_set.add(key) ans = list() while q: c = q.popleft() if c not in del_set: ans.append(c) print(''.join(ans))