每次思考都是一次进步
1、如果要求时间复杂度为O(logn),那么很大可能
class Solution {
public:
vector<int> searchRange(vector<int>& nums, int target) {
int thesize=nums.size();
vector<int> q(2,-1);
if(thesize==0)return q;
int l=0,r=thesize-1,mid;
double t1=target-0.5;
double t2=target+0.5;
while(l<r)
{
mid=l+(r-l)/2;
if(nums[mid]<t1) l=mid+1;
else r=mid;
}
if(nums[l]!=target) return q;
else q[0]=l;
l=0,r=thesize-1;
while(l<r)
{
mid=l+(r-l+1)/2;
if(nums[mid]<t2) l=mid;
else r=mid-1;
}
q[1]=l;
return q;
}
};