LeetCode H-index and H-index II
2015-12-18 14:38
447 查看
题目:
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
has
least
each, his h-index is
Note: If there are several possible values for
the maximum one is taken as the h-index.
Hint:
An easy approach is to sort the array first.
What are the possible values of h-index?
A faster approach is to use extra space.
题意:
给定一个关于论文的引用次数的数组,然后计算关于这个学者的H-index指数。一开始我不太理解这道题目,后来经过网上搜了相关的概念,知道了其实很好理解。
定义如下:
H指数的计算基于其研究者的论文数量及其论文被引用的次数。赫希认为:一个人在其所有学术文章中有N篇论文分别被引用了至少N次,他的H指数就是N。那么具体的计算方法如下:
1、将其发表的所有SCI论文按被引次数从高到低排序;2、从前往后查找排序后的列表,直到某篇论文的序号大于该论文被引次数。所得序号减一即为H指数。
所以首先只要对这个数组中的元素进行排序即可,然后就是就是按照序号和对应的数组中的值比较,如果发现,序号的值比对应数组中的值要大,那么对应的那个序号减一就是H-index的值。这里我采用了一个小技巧,就是在对数组排序的时候,我采用了归并排序,这种算法是刚学,而且对数组进行归并排序,会非常适用,时间复杂度为O(nlogn),会用到递归的思想。
H-index II:
题目:
现在给的数组是按照引用次数从小到大排序的,那么同理,我只需要将这个i从尾开始循环遍历即可。思路与上一题一样。
public int hIndex(int[] citations)
{
int length = citations.length;
if(length == 1)
{
if(citations[0] >= 1)
return 1;
}
int i = 1;
for(i = 1; i < length; i++)
{
if(i > citations[length - i])
break;
}
i = i + 1;
return i;
}
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 with at
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.
Hint:
An easy approach is to sort the array first.
What are the possible values of h-index?
A faster approach is to use extra space.
题意:
给定一个关于论文的引用次数的数组,然后计算关于这个学者的H-index指数。一开始我不太理解这道题目,后来经过网上搜了相关的概念,知道了其实很好理解。
定义如下:
H指数的计算基于其研究者的论文数量及其论文被引用的次数。赫希认为:一个人在其所有学术文章中有N篇论文分别被引用了至少N次,他的H指数就是N。那么具体的计算方法如下:
1、将其发表的所有SCI论文按被引次数从高到低排序;2、从前往后查找排序后的列表,直到某篇论文的序号大于该论文被引次数。所得序号减一即为H指数。
所以首先只要对这个数组中的元素进行排序即可,然后就是就是按照序号和对应的数组中的值比较,如果发现,序号的值比对应数组中的值要大,那么对应的那个序号减一就是H-index的值。这里我采用了一个小技巧,就是在对数组排序的时候,我采用了归并排序,这种算法是刚学,而且对数组进行归并排序,会非常适用,时间复杂度为O(nlogn),会用到递归的思想。
public static int hIndex(int[] citations) { int length = citations.length; sort(citations,0,length - 1); /*for(int j = 0; j < length; j++) System.out.println(citations[j]);*/ int i = 1; for(i = 1; i <= length; i++) { if(i > citations[i-1]) break; } i = i - 1; return i; } public static void sort(int[] data,int left,int right) { if(left >= right) return; int center = (left + right) / 2; sort(data,left,center); //在进行排序的时候,采用递归的方式来做 sort(data,center + 1,right); merge(data,left,center,right); //最后,合并左右两个数组 } public static void merge(int[] data,int left,int center,int right) { int[] tmpArr = new int[data.length]; int mid = center + 1; int third = left; int tmp = left; while(left <= center && mid <= right) { if(data[left] <= data[mid]) tmpArr[third++] = data[mid++]; else tmpArr[third++] = data[left++]; } while(mid <= right) { tmpArr[third++] = data[mid++]; } while(left <= center) { tmpArr[third++] = data[left++]; } while(tmp <= right) { data[tmp] = tmpArr[tmp++]; } }主要是想要练下归并排序算法,两两排序,然后再两两归并。
H-index II:
题目:
现在给的数组是按照引用次数从小到大排序的,那么同理,我只需要将这个i从尾开始循环遍历即可。思路与上一题一样。
public int hIndex(int[] citations)
{
int length = citations.length;
if(length == 1)
{
if(citations[0] >= 1)
return 1;
}
int i = 1;
for(i = 1; i < length; i++)
{
if(i > citations[length - i])
break;
}
i = i + 1;
return i;
}
相关文章推荐
- 利用VBA将excel数据表生成JSON文件(utf8)
- Mysql C API部分函数讲解
- Azure PowerShell 1.0.0以上版本在中国Azure使用的注意事项
- Azure PowerShell 1.0.0以上版本在中国Azure使用的注意事项
- Azure PowerShell 1.0.0以上版本在中国Azure使用的注意事项
- Azure PowerShell 1.0.0以上版本在中国Azure使用的注意事项
- LISP (Locator Identity Separation)协议详解(一)
- Leetcode202: Maximum Product of Word Lengths
- Java创建和解析Json数据方法(二)——org.json包的使用
- Adaboost算法学习
- Sim Card---002
- 修改输入框placeholder文字默认颜色-webkit-input-placeholder
- 需要了解的技术
- 169 Majority Element [LeetCode Java实现]
- hdu-2048 神、上帝以及老天爷
- UIScrollView实战演练
- 运算放大器
- 什么是JAVA构造方法
- 临时表与表变量
- Android ExpendableListView的使用