-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH-Index
More file actions
43 lines (39 loc) · 1.25 KB
/
H-Index
File metadata and controls
43 lines (39 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
public class Solution {
public int hIndex(int[] citations) {
// 排序
Arrays.sort(citations);
int h = 0;
for(int i = 0; i < citations.length; i++){
// 得到当前的H指数
int currH = Math.min(citations[i], citations.length - i);
if(currH > h){
h = currH;
}
}
return h;
}
}
///////////////////////////////
public class Solution {
public int hIndex(int[] citations) {
int[] stats = new int[citations.length + 1];
int n = citations.length;
// 统计各个引用次数对应多少篇文章
for(int i = 0; i < n; i++){
stats[citations[i] <= n ? citations[i] : n] += 1;
}
int sum = 0;
// 找出最大的H指数
for(int i = n; i > 0; i--){
// 引用大于等于i次的文章数量,等于引用大于等于i+1次的文章数量,加上引用等于i次的文章数量
sum += stats[i];
// 如果引用大于等于i次的文章数量,大于引用次数i,说明是H指数
if(sum >= i){
return i;
}
}
return 0;
}
}
///////////////////////
//https://segmentfault.com/a/1190000003794831