O(log(n)), clean python code


  • 0

    Using binary search.

    class Solution(object):
        def findMin(self, nums):
            low, high = 0, len(nums) - 1
            while low <= high:
                mid = (low + high) / 2
                if nums[mid] > nums[-1]:
                    low = mid + 1
                else:
                    if mid > 0 and nums[mid - 1] > nums[-1] or mid == 0:
                        return nums[mid]
                    high = mid - 1
            return nums[low]

  • 0
    Z

    you can replace nums[-1] to nums[high], and then in else, just replace those lines with high = mid


Log in to reply
 

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