原题题目
代码实现(首刷自解)
class Solution {
public:
int minDeletions(string s) {
int ret = 0;
vector<int> v(26,0);
for(const auto& chr:s) ++v[chr-'a'];
sort(v.begin(),v.end(),greater<int>());
int temp = v[0];
for(int i=1;i<v.size();++i)
{
if(!v[i]) break;
if(temp <= v[i])
{
temp = max(temp-1,0);
ret += (v[i] - temp);
}
temp = min(temp,v[i]);
}
return ret;
}
};