My python code fails a sorted array test case?


  • 0
    P
    class Solution(object):
        def findMin(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            left = 0
            right = len(nums) - 1
            
            while left <= right:
                mid = (left + right) // 2
                
                if nums[mid] < nums[mid - 1]:
                    return nums[mid]
                
                # pivot point is to the left of mid
                if nums[mid] < nums[0]:
                    right = mid - 1
                    
                # pivot point is to the right of mid
                if nums[mid] >= nums[0]:
                    left = mid + 1
                    
            return nums[mid]
    

    I thought the all the test cases contained only rotated arrays, but my code fails on test case [1,1,3],


Log in to reply
 

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