4 lines, O(logN)make it most simple.


  • 0
    D

    public int search(int[] nums, int target) {
    if(nums.length ==0) return -1;
    return binary(nums, target,0, nums.length);
    }
    public int binary(int[] nums, int target, int start, int end) {
    if (start >=end) return -1;
    int median = (start+ end)/2;
    if (nums[median] == target) return median;
    return Math.max (binary( nums, target, start, median), binary( nums, target, median +1, end));
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.