Yingying

你必须非常努力,才能看起来毫不费力

153. Find Minimum in Rotated Sorted Array **

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.

https://discuss.leetcode.com/topic/4100/compact-and-clean-c-solution/9

I have thought of this method, but got confused about the ending condition.

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

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/alwaystry/article/details/52347403
个人分类: leetcode
上一篇217. Contains Duplicate *
下一篇多任务深度学习代码
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭