具体思想:
第一直觉没想到还是对的;
具体代码:
class Solution {
public:
int numRabbits(vector<int>& answers) {
int ret=0;
unordered_map<int, int>ump;
for(auto& an:answers){
ump[an]++;
}
for(auto it=ump.begin();it!=ump.end();it++){
int d=it->first;
int n=it->second;
int temp=n/(d+1);
if(n%(d+1)!=0)
temp=temp+1;
ret+=(temp)*(d+1);
}
return ret;
}
};