```
public int hIndex(int[] citations) {
if(citations.length==0) return 0;
int size=citations.length,begin=0,end=size-1,mid=(begin+end)/2;
while(begin<=end){
if(citations[mid]>=size-mid){
if(mid==0||citations[mid-1]<size-mid+1) return size-mid;
else end = mid-1;
}
else begin = mid+1;
mid = (begin+end)/2;
}
return 0;
}
```