JS solution for search insert


  • 0
    S
    var searchInsert = function(nums, target) {
        let low = 0 , high = nums.length-1
        while(low <= high) {
            mid = Math.floor(low + (high-low)/2)
            if(nums[mid] == target){
                return mid
            } else if(nums[mid] > target) {
                high = mid-1
            } else {
                low = mid+1
            }
        }
        return low
    }```

Log in to reply
 

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