Skip to content

Commit a3302b3

Browse files
committed
[:solved] #245
1 parent 3ec0e59 commit a3302b3

File tree

1 file changed

+19
-0
lines changed
  • find-minimum-in-rotated-sorted-array

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def findMin(self, nums: List[int]) -> int:
3+
# You must write an algorithm that runs in O(log n) time. >> Binary Search
4+
# It's possible because the array is sorted.
5+
left, right = 0, len(nums)-1
6+
7+
while left < right:
8+
mid = (left + right) // 2
9+
# If the value at mid is greater than the value at the right end, it means the minimum place to the right of mid.
10+
if nums[mid] > nums[right]:
11+
left = mid + 1
12+
else:
13+
# mid can be minimum number
14+
# But is it possible to solve it with "right=mid-1"? e.g,[4,5,6,7,0,1,2]
15+
right = mid
16+
return nums[left]
17+
18+
19+

0 commit comments

Comments
 (0)