-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHIndex.java
More file actions
38 lines (32 loc) · 938 Bytes
/
HIndex.java
File metadata and controls
38 lines (32 loc) · 938 Bytes
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
import java.util.Arrays;
public class HIndex {
public static int hIndex_sort(int[] citations) {
if (citations == null || citations.length == 0) {
return 0;
}
Arrays.sort(citations);
final int N = citations.length;
for (int i = 0; i < N; i++) {
if (citations[i] >= N - i) {
return N - i;
}
}
return 0;
}
public int hIndex_count(int[] citations) {
if (citations == null || citations.length == 0) {
return 0;
}
final int N = citations.length;
int[] papers = new int[N + 1];
for (int c: citations) {
papers[Math.min(N, c)]++;
}
int h = N; // citation
// find first h that, h paper has at least h citations
for (int count = papers[N]; count < h; count += papers[h]) {
h--;
}
return h;
}
}