Create find_minimum_rotated_array.py

This commit is contained in:
marina 2023-07-31 16:09:47 -07:00 committed by GitHub
parent 06f3c4dd1e
commit 649a881647
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,21 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# author: bt3gl
def find_min(nums):
left, right = 0, len(nums) - 1
while nums[left] > nums[right]:
mid = (left + right) // 2
if nums[mid] < nums[right]:
# note above that it's on right
right = mid
else:
left = mid + 1
return nums[left]