二分模板
int search(vector<int>& nums, int target) {
int left = 0, right = nums.size();
int mid;
while(left < right) {
mid = (left + right) >> 1;
if(nums[mid] == target) return mid;
else if(nums[mid] < target) left = mid + 1;
else right = mid;
}
if(nums[mid] != target) return -1;
return mid;
}
岂能尽如人意,但求无愧我心