LeetCode---154. Find Minimum in Rotated Sorted Array II

题目

给出旋转数组,找出旋转数组中最小的值。旋转数组中可能有重复元素。如:

Example 1:

Input: [1,3,5]
Output: 1

Example 2:

Input: [2,2,2,0,1]
Output: 0

Python题解

class Solution:
    def findMin(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        left, right = 0, len(nums) - 1
        while left < right:
            mid = (left + right) // 2
            if nums[mid] > nums[right]:
                left = mid + 1
            elif nums[mid] < nums[right]:
                right = mid
            else:
                right -= 1
        return nums[left]

猜你喜欢

转载自blog.csdn.net/leel0330/article/details/80524607