Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
373 B
8
Indexable
Never
var searchInsert = function(nums, target) {
    let low = 0;
    let high = nums.length -1;
    
    while(low<=high) {
        let mid = parseInt((low + high) /2); 
        if(nums[mid] == target) {
            return mid;
        } else if (nums[mid] < target) {
            low = mid + 1
        }else {
            high = mid -1;
        }
    }
    return high + 1;
};