# 274. H-Index

141人阅读 评论(0)

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;
}
}


0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：43429次
• 积分：853
• 等级：
• 排名：千里之外
• 原创：8篇
• 转载：240篇
• 译文：0篇
• 评论：5条
文章分类
阅读排行
最新评论