My JS solution


  • 0
    var searchInsert = function(nums, target) {
        const test = nums.indexOf(target);
        if (test !== -1) return test;
        let i = 0;
        while (nums[i] < target) {
            i++;
        }
        return i;
    };
    

Log in to reply
 

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