森林中的兔子 这个有点像坐船问题哈。
class Solution {
public:
int numRabbits(vector
<int>& a
) {
int ans
= 0;
unordered_map
<int,int> mp
;
for(int x
:a
){
mp
[x
+1]++;
}
for(auto it
:mp
){
int x
= it
.first
,y
= it
.second
;
if(y
%x
){
ans
+= (y
/x
+1)*x
;
}else{
ans
+= y
/x
*x
;
}
}
return ans
;
}
};
转载请注明原文地址:https://ipadbbs.8miu.com/read-62234.html