274. H-Index
2016-06-01 16:36
357 查看
题目:
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
in total and each of them had received
researcher has
each and the remaining two with no more than
each, his h-index is
Note: If there are several possible values for
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;
}
}
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
5papers
in total and each of them had received
3, 0, 6, 1, 5citations respectively. Since the
researcher has
3papers withat least
3citations
each and the remaining two with no more than
3citations
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;
}
}
相关文章推荐
- 页面加载就执行的写法
- HttpClient的3种超时
- linux 卸载自带apache httpd 安装apache httpd
- 如何从action传递参数到struts配置文件
- MySql - 主从同步且只同步指定表
- 关于时域、频域和波数域的一些概念
- 安卓xml使用第三方框架Xstream解析
- java传值和传引用
- MyBatis学习4---使用MyBatis_Generator生成Dto、Dao、Mapping
- Android之沉浸式状态栏的实现
- caffe小问题(2):softmaxWithLoss
- GROOVY简单语法实习
- MYSQL查询一周内的数据(最近7天的)、最近一个月、最近三个月数据
- Activity与Service通信之信使(Messenger)
- FastStone Capture 8.4 注册码
- 创建自定义JSR303的验证约束
- JQuery中的事件绑定
- android键盘的回车键修改和监听
- hibernate-hql查询
- Spring加载Properties配置文件的加密解密处理