My Python solution with non-typical Binary-Search


  • 0
    M
    class Solution:
        # @param {integer[]} nums
        # @return {integer}
        def findMin(self, nums):
            lo, hi = 0, len(nums)
            if nums[lo] <= nums[hi-1]:
                return nums[lo]
            while True:
                mi = (lo + hi) >> 1
                if nums[mi] > nums[0]:
                    lo = mi + 1
                else:
                    if nums[mi] < nums[mi - 1]:
                        return nums[mi]
                    hi = mi

Log in to reply
 

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