Easy Java recursive solution


  • 0
    B
    public class Solution {
        public int findMin(int[] nums) {
            return helper(0,nums.length-1,nums);
        }
        private int helper(int l,int r,int[] nums){
            //base case
            if(r==l)return nums[l];
    
            int mid=(l+r)/2;
            if(nums[r]>nums[mid])return helper(l,mid,nums);
            //addtional case
            if(nums[r]==nums[mid]){
                while(mid!=r&&nums[r]==nums[mid])r--;
                return helper(l,r,nums);
            }else
                return helper(mid+1,r,nums);
        }
    }
    

Log in to reply
 

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