public int searchInsert(int[] A, int target) {
// write your code here
for(int i=0;i<A.length;i++){
if(A[i]>=target)
return i;
}
return A.length;
}
}
lintCode 搜索插入位置
最新推荐文章于 2018-04-25 10:51:53 发布
本文介绍了一个简单的算法,用于在一个已排序的整数数组中找到特定目标值的插入位置。通过遍历数组,当遇到大于等于目标值的第一个元素时返回其索引;若目标值大于数组中的所有元素,则返回数组长度作为插入位置。
1万+

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



