Last updated 2 years ago
如果中間的值比最右邊的大,那代表最小值在右區間
如果中間的值比最右邊的小,那代表最小值在左區間
class Solution: def findMin(self, nums: List[int]) -> int: left = 0 right = len(nums) - 1 while left < right: mid = left + (right - left ) // 2 if nums[mid] > nums[right]: left = mid + 1 else: right = mid return nums[left]