Solution in JS


  • 0
    H
    var searchInsert = function(nums, target) {
        nums.push(Number.POSITIVE_INFINITY);
        nums.unshift(Number.NEGATIVE_INFINITY);
        for (var i = 0; i < nums.length - 1; i++) {
            if (target <= nums[i + 1]) {
                return i;
            }
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.