Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LeetCode] 274. H-Index #6

Open
frdmu opened this issue Jul 11, 2021 · 0 comments
Open

[LeetCode] 274. H-Index #6

frdmu opened this issue Jul 11, 2021 · 0 comments

Comments

@frdmu
Copy link
Owner

frdmu commented Jul 11, 2021

Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return compute the researcher's h-index.

According to the definition of h-index on Wikipedia: A scientist has an index h if h of their n papers have at least h citations each, and the other n − h papers have no more than h citations each.

If there are several possible values for h, the maximum one is taken as the h-index.

Example 1:

Input: citations = [3,0,6,1,5]
Output: 3
Explanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively.
Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.

Example 2:

Input: citations = [1,3,1]
Output: 1

计算H指数,维基百科中有解释,并给出了计算方法:

H指数的计算基于其研究者的论文数量及其论文被引用的次数。赫希认为:一个人在其所有学术文章中有N篇论文分别被引用了至少N次,他的H指数就是N。[1][2]如美国耶鲁大学免疫学家理查德·弗来沃发表的900篇文章中,有107篇被引用了107次以上,他的H指数是107。

可以按照如下方法确定某人的H指数:
     -  将其发表的所有SCI论文按被引次数从高到低排序;
     -  从前往后查找排序后的列表,只要当前的引用量大于当前的索引值,则H指数加1,最后得到的结果即为最终的H指数。

用图表示,如下所示:
H

代码如下:

class Solution {
public:
    int hIndex(vector<int>& citations) {
        int h = 0;
        int N = citations.size();
        
        sort(citations.begin(), citations.end(), greater<int>());
        for (int i = 0; i < N; i++) {
            if (citations[i] > i)
                h++;
        }

        return h;
    }
};

有一说一,这题出的不咋地,好好的一个概念非得换成难以理解的说法,让人题都读的费劲。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant