```
public class Solution {
public int searchInsert(int[] nums, int target) {
if(nums[0]>target){return 0;}
if(nums.length==1 && nums[0]<target){
return 1;
}
for(int i=0;i<nums.length-1;i++){
int n=i;
if(nums[i]==target){
return n;
}//if
if(nums[i]<target && target<nums[i+1]){//i+1 so we need to consider len==1
return i+1;
}
}//for
if(nums[nums.length-1]>=target)return nums.length-1;
if(nums[nums.length-1]<target)return nums.length;
return 0;
}
```

}