Find Minimum in Rotated Sorted Array

题目信息:

Find Minimum in Rotated Sorted Array_第1张图片

思路:二分法查找:

<span style="font-size:18px;">class Solution:
    # @param num, a list of integer
    # @return an integer
    def findMin(self, num):
        start = 0
        end = len(num) - 1
        while num[start] > num[end]:
            middle = (start + end )/2
            if num[middle] > num[start]:
                start = middle + 1
            else:
                end = middle
        return num[start]</span>

顺便吐槽下leetcode关于python的测评,我用下面的代码竟然也accept了。。。。

<span style="font-size:18px;"># class Solution:
#     # @param num, a list of integer
#     # @return an integer
#     def findMin(self, num):
#         num.sort()
#         return num[0]</span>
直接排序竟然也行,汗。。。。。

你可能感兴趣的:(LeetCode,python)