LeetCode 274. H-Index Posted on 2021-07-11 Edited on 2024-11-24 In LeetCode SortCounting Sort123456789class Solution {public: int hIndex(vector<int>& citations) { sort(citations.begin(), citations.end()); int i = citations.size() - 1, h = 0; while (i >= 0 && citations[i] > h) ++h, --i; return h; }};12345678910111213class Solution {public: int hIndex(vector<int>& citations) { int n = citations.size(), c = 0; vector<int> cnt(n + 1); for (auto &x : citations) ++cnt[min(x, n)]; for (int i = n; i >= 0; i--) if ((c += cnt[i]) >= i) return i; return 0; }};