-
Notifications
You must be signed in to change notification settings - Fork 0
/
HIndex.java
41 lines (31 loc) · 877 Bytes
/
HIndex.java
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
import java.util.Arrays;
public class HIndex {
public int hIndex(int[] citations) {
if (citations.length == 1) {
if (citations[0] > 0) {
return 1;
}
return 0;
}
Arrays.sort(citations);
int countFori = citations.length;
for (int i = citations.length - 1; i >= 0; i--) {
int count = 0;
for (int citation : citations) {
if ( citation >= countFori) {
count++;
}
}
if (count >= countFori) {
return countFori;
}
countFori--;
}
return 0;
}
public static void main(String[] args) {
HIndex hIndex = new HIndex();
int[] values = {3,0,6,1,5};
System.out.println(hIndex.hIndex(values));
}
}