题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
"""
看了前面老哥的代码,去运行了下报错,这里修改了下
"""
def del_min_sr(sr):
# 字符对应出现次数的字典
dic_sr = {}
# 最小的出现次数
minsr = sys.maxsize
# 出现次数最少的字符列表
lsr = []
for i in sr:
if dic_sr.get(i) != None:
dic_sr[i] += 1
else:
dic_sr[i] = 1
for a in dic_sr.keys():
minsr = min(minsr, dic_sr.get(a))
for vo in dic_sr.keys():
if dic_sr[vo] == minsr:
lsr.append(vo)
for re in lsr:
sr = sr.replace(re, '')
return sr
while True:
try:
_sr = input().split('\r')
for i in _sr:
print(del_min_sr(i))
except EOFError:
break