class Solution {
public:
vector<int> searchRange(vector<int>& nums, int target) {
if (nums.empty()) {
return {-1, -1};
}
int l = 0, r = nums.size() - 1;
while (l < r) { // 找第一个target
int mid = l + r >> 1;
if (nums[mid] >= target) r = mid;
else l = mid + 1;
}
int t = l;
if (target != nums[r]) return {-1, -1};
l = 0, r = nums.size() - 1;
while (l < r) { //找最后一个是target
int mid = l + r + 1 >> 1;
if (nums[mid] <= target) l = mid;
else r = mid - 1;
}
int k = r;
return {t, k};
}
};