classSolution { public: vector<int> searchRange(vector<int>& nums, int target){ int len = nums.size(); int l = 0; int r = len - 1; int ans1 = -1; int ans2 = -1; while(l <= r) { int mid = (l+r)/2; if(nums[mid]==target) { int i = mid; while(i >= 0 && nums[i] == nums[mid]) i--; ans1 = i + 1; i = mid; while(i < len && nums[i] == nums[mid]) i++; ans2 = i - 1; break; } elseif(nums[mid]<target) l=mid+1; else r=mid-1; } vector<int>ans={ans1,ans2}; return ans; } };