阅读理解
- 题意要找的就是nums[mid] >= len - mid的第一个点
- 即找右半段的左端点
- 模板一
class Solution {
public int hIndex(int[] citations) {
if(citations == null || citations.length == 0)
return 0;
int n = citations.length;
if(citations[n-1] == 0)
return 0;
int l = 0;
int r = n - 1;
while(l < r){
int mid = l + r >> 1;
if(citations[mid] >= n - mid)
r = mid;
else
l = mid + 1;
}
return n - r;
}
}