35. 搜索插入位置 - 力扣(LeetCode)
目录
运行结果
代码

35. 搜索插入位置 - 力扣(LeetCode)
目录
运行结果
代码
class Solution {
public:
int searchInsert(vector& nums, int target) {
int beg = 0, end = nums.size();
while(beg != end){
int mid = beg + (end - beg) / 2;
if(nums[mid] == target) return mid;
nums[mid] > target ? end = mid : beg = mid + 1;
}
return beg;
}
};