记录力扣刷题qaq
题目如下:
题目
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/033e2daafa88012ef77fd90bad1113ed.png)
思路:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/7c4d860c8671a8eb7768e43d9a2736de.png)
代码如下:
int searchInsert(int* nums, int numsSize, int target) {
int left = 0, right = numsSize - 1, ans = numsSize;
while (left <= right) {
int mid = ((right - left) >> 1) + left;
if (target <= nums[mid]) {
ans = mid;
right = mid - 1;
} else {
left = mid + 1;
}
}
return ans;
}