题解 | #删除字符串中出现次数最少的字符#
''' 写复杂了,本质上是用set去重,再用字典记录每个字符的数量,排序后去掉最小的字符,有很多地方还可以优化 ''' x = input() x_list = list(x) x_set = set(x_list) x_dict = {} for i in x_set: x_dict[i] = x.count(i) x_key = dict(sorted(x_dict.items(),key=lambda x:x[1],reverse = False)).keys() ans_list = [] for key in x_key: if not ans_list: ans_list.append(key) elif x_dict[key]==x_dict[ans_list[-1]]: ans_list.append(key) elif x_dict[key] > x_dict[ans_list[-1]]: break else: break for key in ans_list: x = x.replace(key,'') print(x)