题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
#字符串处理函数 def processStr(line): ch_nums={} #统计字符频率 for index in range(len(line)): curch = line[index] nums = ch_nums.get(curch) if nums: ch_nums.__setitem__(curch, nums+1) else: ch_nums.__setitem__(curch, 1) values = ch_nums.values() minValues = min(values) #根据最小频率,确定需要删除的字符 delChar = [] for key in ch_nums.keys(): if ch_nums.get(key)==minValues: delChar.append(key) #输出删除后的字符串 res = '' for i in range(len(line)): if line[i] not in delChar: res+=line[i] return res while 1: try: line = input().strip() print(processStr(line)) except EOFError: break