```
public class Solution {
public int hIndex(int[] citations) {
if(citations.length == 0) {
return 0;
}
Arrays.sort (citations);
for(int i = citations.length - 1, h = 0; h < citations.length; h++,i--) {
if (citations[i] <= h) {
return Math.max(citations[i],h);
}
}
return Math.min(citations.length,citations[0]);
}
}
```