public class Solution {
public int searchInsert(int[] A, int target) {
int index = A.length;
if(A.length == 1){
if(target <= A[0])
return 0;
else{
return 1;
}
}
if(target < A[(int) index / 2]){
int[] b = new int[index/2];
for(int i = 0 ; i < b.length ; i++){
b[i] = A[i];
}
return searchInsert(b,target);
}else if(target > A[(int) index / 2]){
int[] b = new int[index - index/2];
for(int i = 0 ; i < b.length ; i++){
b[i] = A[i + index/2];
}
return index/2 + searchInsert(b,target);
}else{
return index / 2;
}
}
}
Search Insert Position
最新推荐文章于 2019-05-31 00:39:10 发布