classSolution { public: vector<int> searchRange(vector<int>& nums, int target){ int n = nums.size(); int l = 0; int r = n - 1; while(l <= r){ int mid = l + r >> 1; if(nums[mid] < target){ l = mid + 1; }else{ r = mid - 1; } } if(l == n || nums[l] != target){ return {-1, -1}; } r = n - 1; vector<int> ans; ans.push_back(l); while(l <= r){ int mid = l + r >> 1; if(nums[mid] == target){ l = mid + 1; }else{ r = mid - 1; } } ans.push_back(r); return ans;
classSolution { public: intfindMin(vector<int>& nums){ int n = nums.size(); int l = -1; int r = nums.size() - 1; while(l + 1 < r){ int mid = l + r >> 1; if(nums[mid] < nums[n - 1]){ r = mid; }else{ l = mid; } } return nums[r]; } };