11[#0153-find-minimum-in-rotated-sorted-array]
2- = 153. Find Minimum in Rotated Sorted Array
2+ = 153. 寻找旋转排序数组中的最小值
33
4- { leetcode} /problems/find-minimum-in-rotated-sorted-array/[LeetCode - Find Minimum in Rotated Sorted Array ^]
4+ https:// leetcode.cn /problems/find-minimum-in-rotated-sorted-array/[LeetCode - 153. 寻找旋转排序数组中的最小值 ^]
55
6- Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
6+ 已知一个长度为 `n` 的数组,预先按照升序排列,经由 `1` 到 `n` 次 *旋转* 后,得到输入数组。例如,原数组 `nums = [0,1,2,4,5,6,7]` 在变化后可能得到:
77
8- (i.e., `[0,1,2,4,5,6,7]` might become `[4,5,6,7,0,1,2]` ).
8+ * 若旋转 `4` 次,则可以得到 `[4,5,6,7,0,1,2]`
9+ * 若旋转 `7` 次,则可以得到 `[0,1,2,4,5,6,7]`
910
10- Find the minimum element.
11+ 注意,数组 `[a[0], a[1], a[2], ..., a[n-1]]` *旋转一次* 的结果为数组 `[a[n-1], a[0], a[1], a[2], ..., a[n-2]]` 。
1112
12- You may assume no duplicate exists in the array.
13+ 给你一个元素值 *互不相同* 的数组 `nums` ,它原来是一个升序排列的数组,并按上述情形进行了多次旋转。请你找出并返回数组中的 *最小元素* 。
1314
14- *Example 1:*
15+ 你必须设计一个时间复杂度为 stem:[O(log n)] 的算法解决此问题。
1516
16- [subs="verbatim,quotes,macros"]
17- ----
18- *Input:* [3,4,5,1,2]
19- *Output:* 1
20- ----
17+ *示例 1:*
18+
19+ ....
20+ 输入:nums = [3,4,5,1,2]
21+ 输出:1
22+ 解释:原数组为 [1,2,3,4,5] ,旋转 3 次得到输入数组。
23+ ....
24+
25+ *示例 2:*
26+
27+ ....
28+ 输入:nums = [4,5,6,7,0,1,2]
29+ 输出:0
30+ 解释:原数组为 [0,1,2,4,5,6,7] ,旋转 3 次得到输入数组。
31+ ....
32+
33+ *示例 3:*
34+
35+ ....
36+ 输入:nums = [11,13,15,17]
37+ 输出:11
38+ 解释:原数组为 [11,13,15,17] ,旋转 4 次得到输入数组。
39+ ....
40+
41+ *提示:*
42+
43+ * `n == nums.length`
44+ * `+1 <= n <= 5000+`
45+ * `+-5000 <= nums[i] <= 5000+`
46+ * `nums` 中的所有整数 *互不相同*
47+ * `nums` 原来是一个升序排序的数组,并进行了 `1` 至 `n` 次旋转
2148
22- *Example 2:*
2349
24- [subs="verbatim,quotes,macros"]
25- ----
26- *Input:* [4,5,6,7,0,1,2]
27- *Output:* 0
28- ----
2950
3051== 思路分析
3152
3253最省事的方式当然是遍历,但是,中等难度的题目不可能一个遍历就解决了。
3354
3455针对有序数组,首先想到的就是二分查找。但是,这里的二分查找有需要做些特别处理:要判断最低点在哪个区间。
3556
57+ 只要聚焦于拥有更低点的区间即可。
58+
3659image::images/0153-01.png[{image_attr}]
3760
3861image::images/0153-02.png[{image_attr}]
@@ -57,8 +80,18 @@ include::{sourcedir}/_0153_FindMinimumInRotatedSortedArray.java[tag=answer]
5780include::{sourcedir}/_0153_FindMinimumInRotatedSortedArray_2.java[tag=answer]
5881----
5982--
83+
84+ 三刷::
85+ +
86+ --
87+ [{java_src_attr}]
88+ ----
89+ include::{sourcedir}/_0153_FindMinimumInRotatedSortedArray_3.java[tag=answer]
90+ ----
91+ --
6092====
6193
94+
6295== 参考资料
6396
6497. https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/solutions/698479/xun-zhao-xuan-zhuan-pai-xu-shu-zu-zhong-5irwp/[153. 寻找旋转排序数组中的最小值 - 官方题解^]
0 commit comments