-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHIndex.java
More file actions
39 lines (33 loc) · 1006 Bytes
/
HIndex.java
File metadata and controls
39 lines (33 loc) · 1006 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
39
import java.util.*;
public class HIndex {
public int hIndex(int[] citations) {
if (citations.length == 0) {
return 0;
} else if (citations.length == 1) {
return Math.min(citations[0], 1);
}
Arrays.sort(citations);
int hIndex = 0;
int size = citations.length;
int prevVal = Integer.MAX_VALUE;
for (int i = 0; i < size; i++) {
int val = Math.min(citations[i], i + 1);
int rem = size - (i + 1);
if (hIndex < val && size - val >= rem && prevVal > val) {
hIndex = val;
} else {
return hIndex;
}
prevVal = citations[i];
}
return hIndex;
}
public void run() {
int[] citations = {3,0,6,1,5};
// int[] citations = {0, 1};
// int[] citations = {1, 2};
// int[] citations = {11, 15};
int ret = hIndex(citations);
System.out.println(ret);
}
}