[leetcode]Find Minimum in Rotated Sorted Array II @ Python


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

解题思路:这道题和上一道题的区别是,数组中可能有相同的数。那么,分下列几种情况:

代码:

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[L]:
                L = M + 1
            elif num[M] < num[R]:
                R = M
            else:
                L += 1
        return num[L]

                

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM