Skip to content

Commit 6ce7641

Browse files
committed
solve find minimum in rotated sorted array
1 parent 0320536 commit 6ce7641

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
# TC: O(log(n)) - The search space is halved each round until the minimum is found
3+
# SC: O(1) - Only a few extra variables are used regardless of input size
4+
def findMin(self, nums: List[int]) -> int:
5+
low, high = 0, len(nums) - 1
6+
7+
while low < high:
8+
mid = (high + low) // 2
9+
10+
if nums[mid] > nums[high]:
11+
low = mid + 1
12+
else:
13+
high = mid
14+
15+
return nums[low]

0 commit comments

Comments
 (0)