就是一个二分查找的问题
public int searchInsert(int[] A, int target) {
int high = A.length-1;
int low = 0,middle=0;
while(low <= high){
int midindex = (low+high)/2;
middle = A[midindex];
if(middle == target) return midindex;
if(middle > target)high=midindex-1;
if(middle < target)low=midindex+1;
}
return low;
}
如果查找不到,则返回low,就是要插入的位置