题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
string str = "";
cin >> str;
unordered_map<char, int> m;
for(char c : str){
m[c]++;
}
vector<int> tmp;
for(auto iter = m.begin(); iter != m.end(); iter++){
tmp.push_back(iter->second);
}
sort(tmp.begin(), tmp.end());
string res = "";
for(char c : str){
if(m[c] != tmp[0]){
res += c;
}
}
cout << res << endl;
return 0;
}
华为题库题解 文章被收录于专栏
牛客华为题库的题解