题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; unordered_map<char, int> my_map; for (int i = 0; i < s.size(); i++) { my_map[s[i]]++; } int min = INT_MAX; for (auto it = my_map.begin(); it != my_map.end(); it++) { if (it->second < min) { min = it->second; } } unordered_set<char> delete_set; for (auto it = my_map.begin(); it != my_map.end(); it++) { if (it->second == min) { delete_set.insert(it->first); } } for (int i = 0; i < s.size(); ) { if (delete_set.find(s[i]) != delete_set.end()) { s.erase(i, 1); } else { i++; } } cout << s << endl; return 0; }#菜鸡的自救#