思路:
与AcWing 789一致
class Solution { public: vector<int> searchRange(vector<int>& nums, int target) { if (nums.size() == 0) return {-1, -1}; int begin, end; int l = 0, r = nums.size() - 1; while (l < r) { int mid = l + r >> 1; if (nums[mid] >= target) r = mid; else l = mid + 1; } if (nums[l] != target) return {-1, -1}; else { begin = l; int l = 0, r = nums.size() - 1; while (l < r) { int mid = l + r + 1 >> 1; if (nums[mid] <= target) l = mid; else r = mid - 1; } end = l; } return {begin, end}; } };