```
public int searchInsert(int[] nums, int target) {
// first element
if ((target == nums[0]) || (target < nums[0]) ) return 0;
int temp = nums[0];
int i = 1;
for(i = 1; i<nums.length; i++) {
if (target == nums[i]) return i;
else if (target > temp && target < nums[i]) return i;
else temp = nums[i];
}
return i;
}
```