leetcode

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

0274.cpp (393B)


      1 class Solution {
      2     static int arr[5001];
      3 
      4   public:
      5     int hIndex(vector<int> &citations) {
      6         memset(arr, 0x00, sizeof(arr));
      7         for (int n : citations)
      8             arr[n]++;
      9 
     10         int total = 0;
     11         for (int i = 5000; i >= 0; i--) {
     12             total += arr[i];
     13             if (total >= i) return i;
     14         }
     15 
     16         return -1;
     17     }
     18 };
     19 
     20 int Solution::arr[5001] = {0};