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

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

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")

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

相关推荐

Beeee0927:正确的建议
点赞 评论 收藏
分享
03-05 11:31
已编辑
复旦大学 算法工程师
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客企业服务