题目描述:
第一次提交:O(N)
class Solution: def findMin(self, nums: List[int]) -> int: if not nums: return l,r = 0,len(nums)-1 while l<r: if nums[l]>nums[r]: l += 1 else: r -= 1 return nums[l]
方法二:二分 O(logn)
class Solution: def findMin(self, nums: List[int]) -> int: left, right = 0, len(nums) - 1 while left < right: mid = (left + right) // 2 if nums[mid] > nums[right]: left = mid + 1 else: right = mid return nums[left]