class Solution { public: int hIndex(vector<int>& citations) { int n = citations.size(); vector<int> buck(n+1, 0); for (auto c : citations) { if (c > n) c = n; buck[c]++; } int cnt = 0; for (int i = n; i >= 0; --i) { cnt += buck[i]; if (cnt >= i) return i; } return -1; // never reach here } };