思路
hash表存val值的个数t,如果 t能被 val+1 整除,sum加上t;如果不能被整除,加上(t/(val+1)+1)*(val+1)
class Solution {
public:
int numRabbits(vector<int>& answers) {
map<int,int> mp;
for(auto it : answers){
mp[it] ++ ;
}
int sum = 0 ;
for(auto it : mp){
int val = it.first, t = it.second;
sum+=((t-1)/(val+1)+1)*(val+1);
}
return sum;
}
};