Go simple


  • 0
    D
    func searchInsert(nums []int, target int) int {
    	l := 0
    	r := len(nums) - 1
    	for (r >= l) {
    		mid := l + (r - l) / 2
    		if (nums[mid] == target) {
    			return mid
    		} else if (nums[mid] > target) {
    			r = mid - 1;
    
    		} else {
    			l = mid + 1;
    		}
    	}
    	return l
    }
    

Log in to reply
 

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