博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Find Minimum in Rotated Sorted Array
阅读量:6997 次
发布时间:2019-06-27

本文共 602 字,大约阅读时间需要 2 分钟。

Suppose a sorted array is rotated at some pivot unknown to you beforehand.

(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).

Find the minimum element.

You may assume no duplicate exists in the array.

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

 

转载于:https://www.cnblogs.com/sherylwang/p/5496571.html

你可能感兴趣的文章