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

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

https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9?channelPut=w25springcamp

#include <bits/stdc++.h>// 万能头

using namespace std;

int main() {

    string s;

    while(cin>>s){

    int mi=1e6;

    unordered_map<char,int>m;// 用来存储每个字符出现的次数 也可以用数组来代替

    int n=s.length();

    for(auto x:s){// 开始遍历

        m[x]++;

    }

    for(auto x:s){// 找寻出现的最小次数

        mi=min(mi,m[x]);

    }

    for(auto &x:s){

        if(m[x]==mi)continue;

        cout<<x; // 最后输出

     }

    }

}

// #牛客春招刷题训练营# + 链接

// 64 位输出请用 printf("%lld")

#牛客创作赏金赛#
全部评论

相关推荐

牛客773130651号:巨佬,简历模板换成上下的,左右的很烦,hr看着不爽。。。科大随便乱杀,建议能保研就保研,不行也得考一下 ,985硕去干算法,比开发强多了。开发许多双非都能搞,学历优势用不上,算法有门槛
点赞 评论 收藏
分享
自由水:笑死了,敢这么面试不敢让别人说
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客企业服务