```
public class Solution {
public int hIndex(int[] citations) {
int[] counts = new int[citations.length + 1];
for (int c : citations) {
counts[Math.min(citations.length, c)]++;
}
int sum = 0;
for (int i=citations.length; i>=0; i--) {
sum += counts[i];
if (sum >= i) {
return i;
}
}
return 0;
}
}
```