leetcode-274-H-Index

描述


Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index.

According to the definition of h-index on Wikipedia: “A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each.”

Example:

1
2
3
4
5
6
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, her h-index is 3.

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

分析


这题要求我们求H指数,思路不复杂,将某人发表的所有 SCI 论文按照引用次数从高到低排序,从高到低编号为 0,1,2 … n,当 n >= 引用数时,这个值就是某人的 H 指数。这个指数可以用来评估研究人员的学术产出数量和学术产出水平。

解决方案1(Java)


在 Java 中,自定义 int 类型的 compare 方法还得先把 int 转换成 Integer,见 https://stackoverflow.com/questions/7414299/sorting-int-array-in-descending-order ,索性用从低到高的顺序,只要序号对了就行。如果用 Python 就直观多了。

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public int hIndex(int[] citations) {
Arrays.sort(citations);

int length = citations.length;
for (int i = length-1; i >= 0; i--) {
if (length-i-1 >= citations[i]) {
return length-i-1;
}
}
return citations.length;
}
}

解决方案2(Python)


1
2
3
4
5
6
7
8
9
10
class Solution:
def hIndex(self, citations):
"""
:type citations: List[int]
:rtype: int
"""
for i, v in enumerate(sorted(citations, reverse=True)):
if i >= v:
return i;
return len(citations);

相关问题


题目来源