LeetCode---153. Find Minimum in Rotated Sorted Array

xiaoxiao2021-02-28  4

题目

给出一个旋转数组,找出旋转数组中最小的值。如:

Example 1:

Input: [3,4,5,1,2] Output: 1 Example 2:

Input: [4,5,6,7,0,1,2] Output: 0

Python题解

class Solution(object): 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 else: right = mid return nums[left]
转载请注明原文地址: https://www.6miu.com/read-1600099.html

最新回复(0)