class Solution {
public:
vector<int> searchRange(vector<int>& nums, int target) {
vector<int> res;
vector<int> xxx;
xxx.push_back(-1);
xxx.push_back(-1);
int left=0,right=nums.size()-1;
while(left<=right)
{
int mid=(right+left)/2;
if(nums[mid]>target)
right=mid-1;
else if(nums[mid] < target)
left=mid+1;
else
{
int t=mid;
while(t>=0 && nums[t]==target)
t--;
res.push_back(t+1);
while(mid<=right && nums[++mid] == target)
;
res.push_back(mid-1);
return res;
}
}
return xxx;
}
};
转载于:https://www.cnblogs.com/yanqi110/p/4974296.html
相关资源:数据结构—成绩单生成器