题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
#一开始以为要分三种情况,即abb,aabbddd,ddddd,后来发现不用,都用最后那几行统一处理即可 while True: try: s=input() ss=set(s) adict={} snew='' for i in ss: adict[i]=s.count(i) alist=sorted(adict.items(),key=lambda stu:stu[1]) # print(alist) # if alist[0][1]<alist[1][1]: # print(s.replace(alist[0][0],'')) # elif alist[0]==alist[-1]: # print() # else : subs = '' for item in alist: if item[1]==alist[0][1]: subs+=item[0] for i in subs: s=s.replace(i,'') print(s) except: break