share a simple C++ recursive solution


  • 1
    B
    int findMin(vector<int>& nums) {
            return findMin(0, nums.size()-1, nums);
        }
    
    int findMin(int low, int high, vector<int>& nums){
            if(low==high)
                return nums[low];
            
            int mid=(low+high)/2;
            
            if(nums[low]==nums[mid])
                return min(findMin(low, mid, nums), findMin(mid+1, high, nums));
                
            return nums[low]>nums[mid] ? findMin(low, mid, nums) : min(nums[low], findMin(mid+1, high, nums));
        }

Log in to reply
 

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