leetcode

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

1608.cpp (422B)


      1 class Solution {
      2   public:
      3     int specialArray(const vector<int> &nums) const {
      4         static int count[102];
      5         const int n = size(nums);
      6 
      7         memset(count, 0x00, sizeof(count));
      8         for (const int m : nums)
      9             count[min(n, m)]++;
     10         for (int i = size(nums); i >= 0; i--) {
     11             count[i] += count[i + 1];
     12             if (count[i] == i) return i;
     13         }
     14 
     15         return -1;
     16     }
     17 };