力扣35
--((right - left) >> 1) + left防止数据溢出
class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
int n = nums.size();
int lf = 0,rt = n - 1,ans = n;
while(lf <= rt){
int md = ((rt - lf) >> 1) + lf;
if(nums[md] >= target){
ans = md;
rt = md -1;
}else lf = md + 1;
}
return ans;
}
};
1701

被折叠的 条评论
为什么被折叠?



