recursion solution


  • 0
    X

    public static int findMin(int[] nums) {
    if(nums == null || nums.length == 0) return 0;
    return find(nums, 0, nums.length - 1);
    }

    public static int find(int[] nums,int start,int end){
    	if(start == end) return nums[start];
    	int min = nums[start];
    	int mid = (start + end)/2;
    	if(nums[end] < nums[mid]) min = Math.min(min, find(nums, mid +1, end));
    	else if(nums[end] >= nums[mid]) min = Math.min(min, find(nums,start,mid));
    	return min;
    }

Log in to reply
 

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