题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
x = input() if len(x) in range(1,21) and x.islower(): strs = list(x) word = list(set(strs)) counta = {} # 创建一个字典, 记录每个字母出现的次数 for i in word: counta[i] = x.count(i) minwords = min(counta.values()) # 找出最少出现次数 for k,v in counta.items(): if v == minwords: # 找出最少出现次数的字母 for times in range(v): ### 根据元素的个数, 删除k(目标字母)多少次 strs.remove(k) print("".join(strs))