Skip to content

Commit 1fc5dcf

Browse files
committed
Add week 9 solutions: find-minimum-in-rotated-sorted-array
1 parent db0d430 commit 1fc5dcf

File tree

1 file changed

+19
-0
lines changed

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+
/**
2+
* https://leetcode.com/problems/find-minimum-in-rotated-sorted-array
3+
* time complexity : O(log n)
4+
* space complexity : O(1)
5+
*/
6+
7+
function findMin(nums: number[]): number {
8+
let left = 0;
9+
let right = nums.length - 1;
10+
11+
while (left < right) {
12+
const mid = Math.floor((left + right) / 2);
13+
14+
if (nums[mid] > nums[right]) left = mid + 1;
15+
else right = mid;
16+
}
17+
18+
return nums[left];
19+
};

0 commit comments

Comments
 (0)