题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
def remove_least_frequent_chars(s): # 统计每个字符的出现次数 char_count = {} for char in s: if char in char_count: char_count[char] += 1 else: char_count[char] = 1 # 找出出现次数最少的字符的出现次数 min_count = min(char_count.values()) # 构建并返回一个新字符串,只包含出现次数不是最少的字符 return "".join(char for char in s if char_count[char] != min_count) # 输入 s = input() # 输出 print(remove_least_frequent_chars(s))