leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0781.cpp (451B)


      1 class Solution {
      2     static const int size = 1001;
      3 
      4   public:
      5     int numRabbits(const vector<int> &answers) const {
      6         int count[size];
      7 
      8         memset(count, 0x00, sizeof(count));
      9         for (const int n : answers)
     10             count[n]++;
     11 
     12         int res = count[0];
     13         for (int i = 1; i < size; i++) {
     14             if (!count[i]) continue;
     15             res += ((count[i] + i) / (i + 1)) * (i + 1);
     16         }
     17 
     18         return res;
     19     }
     20 };