二分法查找,如果找到就返回索引,找不到就返回插入该数后的坐标
public static int searchInsert(int[] nums, int target) { int sta = 0,fin = nums.length,mid; while (sta < fin) { mid = (sta + fin )/2; if(nums[mid] < target) sta = mid +1; else fin = mid; } return sta; }
public static int searchInsert(int[] nums, int target) { int sta = 0,fin = nums.length,mid; while (sta < fin) { mid = (sta + fin )/2; if(nums[mid] < target) sta = mid +1; else fin = mid; } return sta; }