[leetcode]Find Minimum in Rotated Sorted Array @ Python

原题地址:https://oj.leetcode.com/problems/find-minimum-in-rotated-sorted-array/

解题思路:话说leetcode上面的二分查找题目真的不少啊。下图是这道题的数组的两种情况,分别去处理就可以了。

 

class Solution:
    # @param num, a list of integer
    # @return an integer
    def findMin(self, num):
        L = 0; R = len(num)-1
        while L < R and num[L] > num[R]:
            M = (L+R)/2
            if num[M] < num[R]:
                R = M
            else:
                L = M+1
        return num[L]
        

 

posted @ 2014-10-23 14:22  南郭子綦  阅读(2870)  评论(0编辑  收藏  举报