leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0781.cpp (451B)
0 class Solution {
1 static const int size = 1001;
3 public:
4 int numRabbits(const vector<int> &answers) const {
5 int count[size];
7 memset(count, 0x00, sizeof(count));
8 for (const int n : answers)
9 count[n]++;
11 int res = count[0];
12 for (int i = 1; i < size; i++) {
13 if (!count[i]) continue;
14 res += ((count[i] + i) / (i + 1)) * (i + 1);
15 }
17 return res;
18 }
19 };