题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
import sys
def run(str):
c_statistics = dict()
l_str = list(str)
c_smalllest = []
result = []
# 有哪些字符
clean_str = set(str)
# 统计每个字符的个数
for c in clean_str:
c_statistics[c] = l_str.count(c)
# 计算哪些字符最小
l_count = c_statistics.values()
smallest = min(l_count)
for k, v in c_statistics.items():
if v == smallest:
c_smalllest.append(k)
# 循环去除最小字符
for c in l_str:
if c not in c_smalllest:
result.append(c)
return ''.join(result)
if __name__== '__main__':
str = sys.stdin.readline().strip()
r = run(str)
print(r)