题目:
题解:
class Solution {public int hIndex(int[] citations) {int left=0,right=citations.length;int mid=0,cnt=0;while(left<right){// +1 防止死循环mid=(left+right+1)>>1;cnt=0;for(int i=0;i<citations.length;i++){if(citations[i]>=mid){cnt++;}}if(cnt>=mid){// 要找的答案在 [mid,right] 区间内left=mid;}else{// 要找的答案在 [0,mid) 区间内right=mid-1;}}return left;}
}