Cover image for Interview Classic 150 Questions P274 H-Index

Interview Classic 150 Questions P274 H-Index


Timeline

Timeline

2025-10-03

init

Counting sort

Problem:

After sorting, citations[i] indicates that there are n-i papers with citations greater than or equal to citations[i]. We can simply iterate over h to find the maximum value.

12345678910111213141516171819202122232425
#include <algorithm>#include <vector>using std::vector;class Solution {    public:        // A researcher's h-index means that he or she has published at least h papers        // and at least h papers have been cited at least h times. If h has multiple possible values, the h-index        // is the largest one.        int hIndex(vector<int> &citations)        {                int n = citations.size();                int h = 0;                std::sort(citations.begin(), citations.end());                for (int i = 1; i <= n; i++) { // Iterate over h                        if (citations[n - i] >= i) {                                h = i;                        }                }                return h;        }};
Loading comments…