题目
约束
题解
class Solution {
public:
vector<int> searchRange(vector<int>& nums, int target) {
int n = nums.size();
vector<int> ans(2, -1);
if (n == 0) return ans;
int l = 0, r = n - 1;
while(l < r){
int mid = (l + r) >> 1;
if(nums[mid] >= target){
r = mid;
}else{
l = mid + 1;
}
}
if(nums[l] != target){
return ans;
}else{
ans[0] = l;
int l1 = 0, r1 = n - 1;
while(l1 < r1){
int mid = (l1 + r1 + 1) >> 1;
if(nums[mid] <= target){
l1 = mid;
}else{
r1 = mid - 1;
}
}
ans[1] = l1;
}
return ans;
}
};
标签:nums,int,l1,mid,789,查找,ans,LeetCode
From: https://www.cnblogs.com/chuixulvcao/p/17100360.html