Skip to content

Commit e71b698

Browse files
committed
add find-minimum-in-rotated-sorted-array solution
1 parent 233036e commit e71b698

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Time complexity O(logn)
3+
Space compexity O(1)
4+
5+
Binary search
6+
"""
7+
8+
class Solution:
9+
10+
def findMin(self, nums: List[int]) -> int:
11+
start = 1
12+
end = len(nums) - 1
13+
14+
while start <= end:
15+
mid = (start + end) // 2
16+
if nums[mid-1] > nums[mid]:
17+
return nums[mid]
18+
if nums[0] < nums[mid]:
19+
start = mid + 1
20+
else:
21+
end = mid - 1
22+
23+
return nums[0]

0 commit comments

Comments
 (0)