Recursive version with handling duplicates


  • 0
    K

    The idea is to find a subregion with its start and end that are strictly increasing and return the start.

    def findMin(self, nums):
    
        left,right=0,len(nums)-1
        
        if len(nums)==1:
            return nums[0]
        if nums[left]<nums[right]:
            return nums[left]
        
        mid=int((right+left)/2)
        
        if  nums[mid]==nums[left] and nums[mid]==nums[right]:
            return min(self.findMin(nums[mid+1:]),self.findMin(nums[:mid+1]))
        elif  nums[mid]>=nums[left]:
            return self.findMin(nums[mid+1:])
        else:
            return self.findMin(nums[:mid+1])

Log in to reply
 

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