Simple Java Solution, but more than one recursive call


  • 0
    N

    public class Solution {
    public int binary(int [] nums, int low, int high) {
    int mid = low + (high-low)/2;
    if(low == high) return nums[high];
    if(low > high) return Integer.MAX_VALUE;
    if(nums[low] <= nums[mid]) return Math.min(nums[low], binary(nums,mid+1, high));
    else return Math.min(binary(nums,low+1,mid), binary(nums, mid+1, high));
    }
    public int findMin(int[] nums) {
    return binary(nums, 0 ,nums.length-1);
    }
    }


  • 0
    E

    Can you format your solution a little bit please?


Log in to reply
 

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