class Solution {

public int searchInsert(int[] nums, int target) {

```
int left=0, right = nums.length -1, mid = 0;
if(target<=nums[left]) return left;
else if(target>nums[right]) return right+1;
else return right;
while(left+1 < right){
mid = left + (right - left)/2;
if( target > nums[mid]) left=mid;
else right = mid;
}
if (target == nums[left]){ return left ;}
else return left+1;
}
```

}