1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| class Solution { public int hIndex(int[] citations) { int n = citations.length; int left = 0, right = n - 1;
int lastIndex = n; while (left <= right) { int mid = (left + right) >>> 1;
if (citations[mid] >= n - mid) { lastIndex = mid; right = mid - 1; } else { left = mid + 1; } }
return n - lastIndex; } }
|