-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH_Index.java
More file actions
37 lines (35 loc) · 1023 Bytes
/
H_Index.java
File metadata and controls
37 lines (35 loc) · 1023 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
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Comparator;
/**
* Created by Administrator on 2016/10/21 0021.
*/
public class H_Index {
public static int hIndex(int[] citations) {
int n = citations.length, i=0;
Integer citation[] = new Integer[n];
for(int a:citations){
citation[i++] = a;
}
PrintStream out = System.out;
Comparator comparator = new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
if(o1 >= o2)return -1;
else return 1;
}
};
Arrays.sort(citation, comparator);
for(i = n - 1;i>=0;i--)
{
if(citation[i] >= i)break;
}
return citation[i];
}
public static void main(String args[]){
int a[] = {3, 0, 6, 1, 5};
PrintStream out = System.out;
int ans = hIndex(a);
out.println(ans);
}
}