The main idea is based on Binary Search: find the first index satisfying citations[index] >= length(citations) - index.

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