排序+贪心
代码
class Solution {
public:
int minDeletions(string s) {
vector<int> mp(26, 0);
for (auto ch : s)
mp[ch - 'a']++;
sort(mp.begin(), mp.end(), greater<int>());
int ans = 0;
int pre = mp[0];
for (int i = 1; i < mp.size(); i++) {
if (pre <= mp[i]) {
pre = max(pre - 1, 0);
ans = mp[i] - pre;
}
else
pre = mp[i];
}
return ans;
}
};