代码实现
public class Day0718 {
public static void main(String[] args) {
int [] nums={1,3,5,7,8,9};
int recur = recur(0, nums.length - 1, 7, nums);
System.out.println(recur);
}
public static int recur(int begin,int end,int target,int []nums){
if(nums==null||nums.length<0||nums[begin]>target
||nums[end]<target||begin>end) return -1;
int mid=(begin+end)/2;
if(nums[mid]>target) {
return recur(begin, mid - 1, target, nums);
}
else if(nums[mid]<target){
return recur(mid+1,end,target,nums);
}else{
return mid;
}
}
}