class Solution {
public int searchInsert(int[] nums, int target) {
int low=0;
int high=nums.length-1;
int mid=0;
while(low<=high){
mid=low+(high-low)/2;
if(nums[mid]==target){
return mid;
}else if(nums[mid]>target){
high=mid-1;
}else{
low=mid+1;
}
}
return low;
}
}
LeetCode精选100题——第35题——搜索插入位置
最新推荐文章于 2024-08-10 09:23:37 发布