搜索插入位置

给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。

你可以假设数组中无重复元素。

function searchInsert(nums, target) {
    let i;
    for(i = 0;i < nums.length;i++){
        let item = nums[i]
        if(item >= target){
            return i
        }
    }
    return i
}

Leecode提交通过

以自己现在的努力程度,还没有资格和别人拼天赋
原文地址:https://www.cnblogs.com/zhenjianyu/p/13346405.html