题解 | 删除字符串中出现次数最少的字符
思路:
1.遍历字符串,用字典记录每个字符出现的次数
2. min()找出最小的字符对应的次数及字符
3. 输出除待删除以外的其他字符
s=input().strip()
countdict={}
for c in s:
countdict[c]=countdict.get(c,0)+1
mincount=min(countdict.values())
delchar=[]
goallist=[]
for k,v in countdict.items():
if v==mincount:
delchar.append(k)
for c in s:
if c not in delchar:
goallist.append(c)
goal=''.join(goallist)
print(goal)