mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Create find_minimum_rotated_array.py
This commit is contained in:
parent
06f3c4dd1e
commit
649a881647
21
searching/find_minimum_rotated_array.py
Normal file
21
searching/find_minimum_rotated_array.py
Normal 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]
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user