class Solution {
public int searchInsert(int[] nums, int target) {
int left=0;
int right = nums.length-1;
int mid= 0;
while(left<=right){
mid = (left+right)/2;
if(nums[mid]<target){
left = mid+1;
}else if(nums[mid]>target){
right = mid -1;
}else{
break;
}
}
if(nums[mid]<target){
mid++;
return mid;
}
return mid;
}
}
Java算法之搜索插入位置
最新推荐文章于 2024-08-18 22:40:28 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)