标签:题目 ref == public int leetcode 二分 problem problems
现在变了,数列是拍好序的,题目要求对数效率,因为x只可能有一个那就二分咯
class Solution {
public:
int hIndex(vector<int>& citations) {
if(citations.size()==0)
return 0;
int len = citations.size();
int l=0;
int r = len-1;
while(l<=r)
{
int mid = (l+r)/2;
if(citations[mid]>len-mid)
{
r = mid-1;
}
else if(citations[mid]<len-mid)
{
l = mid+1;
}
else
{
return len-mid;
}
}
if(l<len&&citations[l]>len-l)
return len-l;
else
return 0;
}
};
标签:题目 ref == public int leetcode 二分 problem problems
原文地址:https://www.cnblogs.com/dacc123/p/12858500.html