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