-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH_Index.java
More file actions
33 lines (29 loc) · 828 Bytes
/
H_Index.java
File metadata and controls
33 lines (29 loc) · 828 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
public static int findH(int[] a) {
int[] c = new int[a.length];
for (int i = 0; i < a.length; i++) {
if (a[i] > a.length - 1)
c[a.length - 1]++;
else
c[a[i] - 1]++;
}
int total=0;
for (int i = c.length - 1; i >= 0; i--) {
total += c[i];
if (i + 1 <= total)
return i + 1;
}
return -1;
}
public static int findH(int[] a) {
// sort the array first (can use bucket sort)
Arrays.sort(a);
int max = 0;
int n = a.length;
for (int i = 0, h = 1; h <= n - i; h++) {
if (n - i >= h)
max = h;
while (h >= a[i])
i++;
}
return max;
}