274. H-Index

来源:互联网 发布:windows api md5 编辑:程序博客网 时间:2024/05/21 13:23

题目:

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.


题意:

给定一个研究者引用次数的数组,写一个功能去计算一个研究者的“高可用次数”(high citations)。h-index ,又称为h指数或h因子(h-factor),是一种评价学术成就的新方法。h代表“高引用次数”(high citations),一名科研人员的h指数是指他至多有h篇论文分别被引用了至少h次。h指数能够比较准确地反映一个人的学术成就。一个人的h指数越高,则表明他的论文影响力越大。

要确定一个人的h指数非常容易,到SCI网站,查出某个人发表的所有SCI论文,让其按被引次数从高到低排列,往下核对,直到某篇论文的序号大于该论文被

引次数,那个序号减去1就是h指数。


思路一:

新建一个数组用来模拟按照引用次数排名的机制,用引用次数作为下标,轮训数组,如果引用次数相同,则将该下标处的值加1,数组长度为给定数组长度加1,将引用次数超过数组长度的部分划归为下标最大处加1,之后利用H指数算法即可找到相应的H指数。

代码:java版:1ms

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;    }}
思路二:

直接将给定的引用次数数组排序,之后直接利用H指数算法处理即可。

代码:4ms

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
原创粉丝点击