mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-06-17 11:29:27 -04:00
Create find_minimum_rotated_array.py
This commit is contained in:
parent
06f3c4dd1e
commit
649a881647
1 changed files with 21 additions and 0 deletions
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…
Add table
Add a link
Reference in a new issue