题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
''' 构造字典,字典的键值对为字母及其次数 然后找出出现次数最小的字符 遍历所有的字符,不添加出现次数最小的字符 ''' while True: try: a = input() a_dict = {} for k in set(a): # 构建字典 a_dict[k] = 0 for i in list(a): # 构建字典 a_dict[i] += 1 min_value = min(a_dict.values()) min_str = [] for k,v in a_dict.items(): # 找出最小出现次数字符 if v == min_value: min_str.append(k) new_chr = '' for i in list(a): # 删除最小出现次数字符 if i not in min_str: new_chr += i print(new_chr) except: break