problem
solution
1 | class Solution { |
- lower bound
class Solution {
public:
vector<int> searchRange(vector<int>& nums, int target) {
if(nums.empty()) return {-1,-1};
int l = 0 , r = nums.size();
while(l<r){
int mid = l +(r-l)/2;
if(nums[mid]>=target) r= mid;
else l = mid+1;
}
if(l<0 || l>nums.size()-1 || nums[l]!=target) return {-1,-1};
r = l;
while(r<nums.size()-1 && nums[r+1] == nums[l] ) r++;
return {l,r};
}
};
```## analysis
- time complexity `O(logn)`
- space complexity `O(1)`