题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
import sys # aabcddd oldStr = sys.stdin.readline() strLength = len(oldStr) oldStrList = list(oldStr)[0 : strLength - 1] minCount = 20 n = strLength - 1 dict1 = {} for i in range(n): tempCount = 0 for j in range(n): if oldStrList[j] == oldStrList[i]: tempCount += 1 # 字典中,键是唯一且不可重复的 # updata()函数只能增加键值不一样的 # 但字母是不一样的,可做键 dict1.update({oldStrList[i]: tempCount}) minCount = min(dict1.values()) allKeys = list(dict1.keys()) for word in allKeys: #通过if判断,找到最小的次数对应的字母 if dict1[word] == minCount: #需要根据次数删除所有的符合条件的字母 times = dict1[word] while int(times) > 0: oldStrList.remove(word) times -= 1 print("".join(oldStrList))