Skip to content

Commit 2e91cf4

Browse files
committed
find minimum in rotated sorted array solution
1 parent 2eb0172 commit 2e91cf4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function findMin(nums: number[]): number {
2+
const n = nums.length;
3+
4+
let l = 0;
5+
let r = n - 1;
6+
7+
while (l < r) {
8+
const mid = Math.floor((l + r) / 2);
9+
10+
if (nums[r] >= nums[mid]) {
11+
r = mid;
12+
} else if (nums[r] < nums[mid]) {
13+
l = mid + 1;
14+
}
15+
}
16+
17+
return nums[l];
18+
}

0 commit comments

Comments
 (0)