leetcode 153

旋转过的严格递增列表, 求其中的最小值.

不难, 注意判断边界条件就可以, 算法复杂度应该是O(logn)

class Solution:
    def findMinInRange(self, nums: List[int], start, end) -> int:
        if start == end:
            return nums[start]
        if nums[start] < nums[end]:
            return nums[start]
        while start < end:
            mid = (start + end) // 2
            if nums[start] > nums[mid]:
                end = mid
                continue
            elif nums[start] == nums[mid]:
                # assert start + 1 == end
                return min(nums[start], nums[end])
            else:
                start = mid
                continue
    def findMin(self, nums: List[int]) -> int:
        len_nums = len(nums)
        result = self.findMinInRange(nums, 0, len_nums-1)
        return result
上一篇:linux常用命令(7)


下一篇:蓝桥杯--特殊的数字