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

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

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

#参考:https://blog.nowcoder.net/n/f00d268a19824d6b868a76f261ee99ff?f=comment
while True:
    try:
        s = input()
        dic, res = {}, ''
        for c in s:
            if c not in dic:
                dic[c] = 1
            else:
                dic[c] += 1
        Min = min(dic.values())
        for c in s:
            if dic[c] != Min:
                res += c
        print(res)
    except:
        break

################################################################################
#####下面是我自己写的,不知道为什么用例通过19/20,assssa下面的代码输出的是assssa#####
################################################################################

'''
while True:
    try:
        inputstring = input()
        if len(inputstring) <= 20:
                
            
            dict_char = {}  # 用字典记录每个字符的出现次数
            min_count = 20 #记录最小出现次数,因为最多20个字符,所以初始化20次
            for char in inputstring:
                if char in dict_char:
                    dict_char[char] += 1 #char对应的值+1
                else:
                    dict_char[char] = 1 #记录新出现的字符
                min_count = min(min_count, dict_char[char])
            
            newlist = []
            for char in inputstring:
                if dict_char[char] > min_count:  # 只保留出现次数大于最小次数的字符
                    newlist.append(char)
            for element in newlist:
                print(element, end='') 
        else:
            break
    except:
        break
'''

全部评论

相关推荐

rndguy:哥们你这个项目看起来做的内容不少,挺厉害的啊orz,搞不好写写论文硕士都能毕业了,怎么会找不到呢?
牛客激励计划
点赞 评论 收藏
分享
吴offer选手:网易这个双机位麻烦死了
投递网易等公司10个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
09-29 11:20
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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