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

if (nums[0] > nums[1]) {

for (int i = nums.length - 1; i >= 0; i--) {

if (nums[i] <= target) {

return i;

}

}

}

for (int i = 0; i < nums.length; i++) {

if (nums[i] >= target) {

return i;

}

}

return nums.length;

}