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)


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