Skip to content

Commit b64ae72

Browse files
committed
feat(binary-search): ✨二分搜索算法解决153
1 parent 3f76bff commit b64ae72

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Binary-Search/153/solution1.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/
3+
*
4+
* 153. 寻找旋转排序数组中的最小值
5+
*
6+
* Medium
7+
*
8+
* 一类题型 33 81
9+
*
10+
* 这道题目相对比较简单
11+
*
12+
* 68ms 99.04%
13+
* 33.6mb 63.89%
14+
*
15+
*/
16+
const findMin = nums => {
17+
let start = 0
18+
let end = nums.length - 1
19+
20+
while (start < end) {
21+
const mid = Math.floor(start + (end - start) / 2)
22+
if (nums[mid] > nums[end]) {
23+
start = mid + 1
24+
} else {
25+
end = mid
26+
}
27+
}
28+
return nums[start]
29+
}

0 commit comments

Comments
 (0)