public static int searchInsert(int[] nums, int target) { int i = 0, j = nums.length - 1; int mid = 0; if (target < nums[0]) return 0; if (target > nums[j]) return nums.length; while (i <= j) { mid = (i + j) / 2; if (target > nums[mid]) { i = mid + 1; } if (target < nums[mid]) { j = mid - 1; } if (target==nums[mid]) return mid; } return i;}复制代码