274. H-Index
H-Index
Solution
public class Solution {
public int hIndex(int[] citations) {
if (citations == null || citations.length == 0) return 0;
int size = citations.length;
int max = citations[0];
for (int i = 1; i < citations.length; i++) {
max = Math.max(max, citations[i]);
}
int[] temp = new int[max + 1];
for(int i = 0; i < citations.length; i ++) {
int cur = citations[i];
for(int j = 0; j <= cur; j ++) {
temp[j] += 1;
}
}
int result = 0;
for(int i = 1; i <= max; i ++) {
if (temp[i] >= i && (temp[i-1]-temp[i] <= size - i)) {
result = Math.max(result, i);
}
}
return result;
}
}Last updated