Find Minimum in Rotated Sorted Array LeetCode solution in Python
1class Solution:2def findMin(self, nums: List[int]) -> int:3if len(nums) == 1 or nums[0] < nums[-1]:4return nums[0]56l, r = 0, len(nums) - 178while l <= r:9mid = l + (r - l) // 21011if mid > 0 and nums[mid - 1] > nums[mid]:12return nums[mid]1314# We compare the middle number and the right index number15# but why we cannot compare it with the left index number?16if nums[mid] > nums[r]:17l = mid + 118else:19r = mid - 1