题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
import sys """ 输入 创建字典;字典的键值对,字母:出现的次数 找出值中的最小值,把最小值的键值对删除 """ s = input() dic = {} # set 底层用的哈希表,容易直接排序改变数组原本的顺序 # ss = set(s) # for key in ss: # value = s.count(key) # dic[key] = value for i in s: if i in dic.keys(): dic[i] = dic[i] + 1 else: dic[i] = 1 # 最小值 min_value = min(dic.values()) # 最小值对应的key min_key = [] for key, value in dic.items(): if value == min_value: min_key.append(key) # 判断是否在最小值key组里面,在的话就跳过,不在就直接输出 for i in s: if i in min_key: pass else: print(i,end="")