Clean python code


  • 0
    class Solution(object):
        def findMin(self, nums):
            low, high = 0, len(nums) - 1
    
            # remove duplicates on sides
            while low < high and nums[low] == nums[high]:
                low += 1
           
            # binary search
            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]

Log in to reply
 

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