二维数组的查找
作者:互联网
代码实现
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;
}
}
}
标签:end,recur,nums,int,mid,二维,查找,数组,return 来源: https://blog.csdn.net/weixin_49263647/article/details/118882338