题解 | #删除字符串中出现次数最少的字符#

删除字符串中出现次数最少的字符

https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9

import sys

str1 = sys.stdin.readline().strip()
str2 = ''
count = dict()
for i in str1:
    if i not in str2:
        str2 += i
for j in str2:
    count[j] = 0
    for k in str1:
        if j == k:
            count[j] = count[j] + 1
    min = count[j]
str3 = ''
for c in count.values():
    if c < min:
        min = c
    else:
        continue
# print(min)
for i in count.keys():
    value1 = count[i]
    if value1 == min:
        str1 = str1.replace(i,"")

print(str1)

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务