```
public int searchInsert(int[] nums, int target) {
if(target > nums[nums.length -1]) return nums.length;
int start = -1, end = nums.length - 1;
while(start != end - 1){
int mid = start + (end - start) / 2;
if(nums[mid] >= target) end = mid;
else start = mid;
}
return end;
}
}
```