Time Complexity = O( Log N )
class Solution:
def findMin(self, nums: List[int]) -> int:
left, right = 0, len(nums) - 1
while left < right:
mid = left + (right - left) // 2
if nums[mid] > nums[right]:
left = mid + 1
elif nums[mid] < nums[right]:
right = mid
elif nums[mid] == nums[right]:
while right > mid and nums[mid] == nums[right]:
right -= 1
return nums[right]
No comments:
Post a Comment