关闭

H-Index

标签: javaleetcode计数排序hindex
231人阅读 评论(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 with at 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.

讲人话:

一名科研人员的h指数是指他至多有h篇论文分别被引用了至少h次。

例如,某人的h指数是20,这表示他已发表的论文中,每篇被引用了至少20次的论文总共有20篇。要确定一个人的h指数非常容易,到SCI网站,查出某个人发表的所有SCI论文,让其按被引次数从高到低排列,往下核对,直到某篇论文的序号大于该论文被引次数,那个序号减去1就是h指数。


这个题比较简单的方法就实现排序,然后按照上面的方法依次找下来即可。如果被引用最少的引用次数都超过了论文数,那么就返回论文数。

例如,有3篇论文,引用次数分别是7,8,9次,那么直接返回3.

代码如下:

public int hIndex(int[] citations) {
	Arrays.sort(citations);
	int n=citations.length;
	for(int i=n-1;i>=0;i--){
		if(citations[i]<n-i)
			return n-i-1;
	}		
	return 0;
}

这样做的时间复杂度是O(nlog(n))。


这个题其实是counting sort的变种。

代码如下:

public class Solution {
    public int hIndex(int[] citations) {  
        int n = citations.length;  
        int[] countArray = new int[n+1];  
          
        for(int i=0; i<n; i++) {  
            if(citations[i] >= n) countArray[n]++; 
            else countArray[citations[i]]++;
        }  
        if(countArray[n]>=n) return n;  
          
        for(int i=n-1; i>=0; i--) {  
            countArray[i] = countArray[i] + countArray[i+1]; 
            if(countArray[i]>=i) return i;  
        }  
        return 0;  
    }  
}

在这里复习一下计数排序,代码如下:

private static void sort(int a[], int b[], int k){  
	//初始化计数数组  
	int c[] = new int[k];  
	for(int i = 0; i<k; i++)  
		c[i] = 0;  
	//计算数组中重复的次数  
	for(int i=0; i<a.length; i++)  
	{  
		c[a[i]] = c[a[i]]+1;  
	}  
	for(int i = 1; i<k; i++)  
	{  
		c[i] = c[i]+c[i-1];  
	}  
	//将a数组中的元素按照顺序复制到b中  
	for(int i = a.length-1; i>=0; i--)  
	{  
		b[c[a[i]]-1] = a[i];  
		c[a[i]] = c[a[i]]-1;  
	}  
}  



0
0
查看评论

计算 h-index

现在有这样一个问题, 求解 h-index.  h-index 是一种衡量一个人论文水平的参数, 其定义为 h篇文章引用超过h. 该参数越大表明一个人的学术水平越高, 但不同行业差别巨大. 一般看来生物领域偏高, 同样生物领域期刊的IF同样高. 下面考虑下面一个算法问题, 已...
  • l88371447
  • l88371447
  • 2017-06-22 23:23
  • 290

leetcode笔记:H-Index

给定一个数组,记载了某研究人员的文章引用次数(每篇文章的引用次数都是非负整数),编写函数计算该研究人员的h指数。
  • liyuefeilong
  • liyuefeilong
  • 2016-02-01 15:31
  • 2061

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-ind...
  • u010455041
  • u010455041
  • 2015-12-03 19:32
  • 414

leetcode 275: H-Index II

Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm? [思路] 二分查找, [CODE] p...
  • xudli
  • xudli
  • 2015-09-05 17:09
  • 2830

leetcode 274. H-Index-h因子|哈希表

原题链接:274. H-Index 【思路】 public class Solution { public int hIndex(int[] citations) { Arrays.sort(citations); int level = 0; ...
  • happyaaaaaaaaaaa
  • happyaaaaaaaaaaa
  • 2016-06-06 13:46
  • 1213

leetcode 274: H-Index

H-Index Total Accepted: 2684 Total Submissions: 11955 Given an array of citations (each citation is a non-negative integer) of a res...
  • xudli
  • xudli
  • 2015-09-05 16:30
  • 3771

LeetCode刷题 (Python) | 275. H-Index II

LeetCode刷题 (Python) | 275. H-Index II
  • Titan0427
  • Titan0427
  • 2016-02-10 17:48
  • 810

[leetcode-274]H-Index(java)

问题描述: 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.Acc...
  • zdavb
  • zdavb
  • 2015-09-03 23:03
  • 1447

[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.Acco...
  • u014673347
  • u014673347
  • 2015-09-05 16:58
  • 1100

【Leet Code】274. H-Index---Medium

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. Acco...
  • lili616
  • lili616
  • 2015-10-29 10:46
  • 230
    个人资料
    • 访问:63451次
    • 积分:2768
    • 等级:
    • 排名:第15331名
    • 原创:215篇
    • 转载:37篇
    • 译文:0篇
    • 评论:6条
    最新评论