Recursive O(log n) python solution


  • 1
    N
    class Solution(object):
        def findMin(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            if len(nums) == 1:
                return nums[0]
            n = len(nums)
            m = n / 2
            # first part from 0..m-1
            # second part from m..n-1
            if nums[0] <= nums[m-1] and nums[m] <= nums[n-1]:
                return min(nums[0], nums[m])
            elif nums[0] <= nums[m-1] and nums[m] >= nums[n-1]:
                return self.findMin(nums[m:n])
            else:
                return self.findMin(nums[:m])

Log in to reply
 

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