35.搜索插入位置

使用二分查找:
class Solution {
public int searchInsert(int[] nums, int target) {
int low = 0,high = nums.length -1;
while(low <= high){
//注意每次循环完都要计算mid
int mid = (low + high)/2;
if(nums[mid] == target){
return mid;
}
if(nums[mid] < target){
low = mid + 1;
}
if(nums[mid] > target){
high = mid -1;
}
}
return low ;
}
}












![[JAVAee]SpringBoot-AOP](https://img-blog.csdnimg.cn/90425924543a410786d19347fcb5ae6c.png)






