# 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."

For example, given citations = [3, 0, 6, 1, 5], which 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 withat least 3 citations each and the remaining two with no more than 3 citations each, his h-index is 3.

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

public class Solution {
public int hIndex(int[] citations) {
int length = citations.length;
if(length==0){
return 0;
}

int[] index = new int[length+1];
for(int i=0; i<length; i++){ //将引用次数作为下标，对相同引用次数的计数。
if(citations[i]>length){
index[length] += 1;
}else{
index[citations[i]] += 1;
}
}

int count = 0;
for(int i=length; i>=0; i--){
count = count + index[i]; //统计大于序号的文章数
if(count>=i){ //如果文章数大于排序序号时，返回H值
return i;
}
}
return 0;
}
}


public class Solution {
public int hIndex(int[] citations) {

Arrays.sort(citations);
int len = citations.length;
if(len==0){
return 0;
}

for(int i=0; i<len; i++){
if(citations[i]>=len-i){
return len-i;
}
}
return 0;
}
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：274. H-Index 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)