二维数组的查找

二维数组的查找
二维数组的查找
二维数组的查找
代码实现

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;
        }
    }
}

参考文献https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/solution/mian-shi-ti-04-er-wei-shu-zu-zhong-de-cha-zhao-zuo/

上一篇:剑指 Offer 28. 对称的二叉树


下一篇:RECUR宣布与三丽鸥建立NFT战略合作关系,首次将标志性品牌Hello Kitty引入数字藏品空间