```
public int hIndex(int[] citations) {
if (citations == null || citations.length == 0) return 0;
int n = citations.length;
int[] c = new int[n + 1];
for (int i : citations) {
if (i > n) i = n;
++c[i];
}
if (c[n] >= n) return n;
for (int i = n - 1; i > 0; --i) {
c[i] += c[i + 1];
if (c[i] >= i) return i;
}
return 0;
}
```