```
public int hIndex(int[] citations) {
int n = citations.length;
int[] hindex = new int[n + 1];
for(int val: citations){
if(val >= n) hindex[n]++;
else hindex[val]++;
}
int sum = 0;
for(int i = n; i > 0; i--){
sum += hindex[i];
if(i <= sum){
sum = Math.max(i, sum - hindex[i]);
break;
}
}
return sum;
}
```