|
1 | 1 | [#0033-search-in-rotated-sorted-array]
|
2 |
| -= 33. Search in Rotated Sorted Array |
| 2 | += 33. 搜索旋转排序数组 |
3 | 3 |
|
4 |
| -{leetcode}/problems/search-in-rotated-sorted-array/[LeetCode - Search in Rotated Sorted Array^] |
| 4 | +https://leetcode.cn/problems/search-in-rotated-sorted-array/[LeetCode - 33. 搜索旋转排序数组 ^] |
5 | 5 |
|
6 |
| -Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. |
| 6 | +整数数组 `nums` 按升序排列,数组中的值 *互不相同* 。 |
7 | 7 |
|
8 |
| -(i.e., `[0,1,2,4,5,6,7]` might become `[4,5,6,7,0,1,2]`). |
| 8 | +在传递给函数之前,`nums` 在预先未知的某个下标 `k`(`+0 <= k < nums.length+`)上进行了 *旋转*,使数组变为 `+[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]+`(下标 *从 0 开始* 计数)。例如, `+[0,1,2,4,5,6,7]+` 在下标 `+3+` 处经旋转后可能变为 `+[4,5,6,7,0,1,2]+` 。 |
9 | 9 |
|
10 |
| -You are given a target value to search. If found in the array return its index, otherwise return `-1`. |
| 10 | +给你 *旋转后* 的数组 `nums` 和一个整数 `target` ,如果 `nums` 中存在这个目标值 `target` ,则返回它的下标,否则返回 `-1` 。 |
11 | 11 |
|
12 |
| -You may assume no duplicate exists in the array. |
| 12 | +你必须设计一个时间复杂度为 stem:[log_2N] 的算法解决此问题。 |
13 | 13 |
|
14 |
| -Your algorithm's runtime complexity must be in the order of _O_(log _n_). |
15 |
| - |
16 |
| -*Example 1:* |
| 14 | +*示例 1:* |
17 | 15 |
|
18 | 16 | [subs="verbatim,quotes,macros"]
|
19 | 17 | ----
|
20 |
| -*Input:* nums = [`4,5,6,7,0,1,2]`, target = 0 |
21 |
| -*Output:* 4 |
| 18 | +输入:nums = [4,5,6,7,0,1,2], target = 0 |
| 19 | +输出:4 |
| 20 | +---- |
22 | 21 |
|
| 22 | +*示例 2:* |
| 23 | + |
| 24 | +[subs="verbatim,quotes,macros"] |
| 25 | +---- |
| 26 | +输入:nums = [4,5,6,7,0,1,2], target = 3 |
| 27 | +输出:-1 |
23 | 28 | ----
|
24 | 29 |
|
25 |
| -*Example 2:* |
| 30 | +*示例 3:* |
26 | 31 |
|
27 | 32 | [subs="verbatim,quotes,macros"]
|
28 | 33 | ----
|
29 |
| -*Input:* nums = [`4,5,6,7,0,1,2]`, target = 3 |
30 |
| -*Output:* -1 |
| 34 | +输入:nums = [1], target = 0 |
| 35 | +输出:-1 |
31 | 36 | ----
|
32 | 37 |
|
| 38 | +*提示:* |
| 39 | + |
| 40 | +* `+1 <= nums.length <= 5000+` |
| 41 | +* `+-10+`^`+4+`^`+ <= nums[i] <= 10+`^`+4+`^ |
| 42 | +* `+nums+` 中的每个值都 *独一无二* |
| 43 | +* 题目数据保证 `+nums+` 在预先未知的某个下标上进行了旋转 |
| 44 | +* `+-10+`^`+4+`^`+ <= target <= 10+`^`+4+`^ |
| 45 | +
|
| 46 | +
|
| 47 | +== 思路分析 |
| 48 | + |
| 49 | +image::images/0033-01.png[{image_attr}] |
33 | 50 |
|
34 | 51 | [[src-0033]]
|
| 52 | +[tabs] |
| 53 | +==== |
| 54 | +一刷:: |
| 55 | ++ |
| 56 | +-- |
35 | 57 | [{java_src_attr}]
|
36 | 58 | ----
|
37 | 59 | include::{sourcedir}/_0033_SearchInRotatedSortedArray.java[tag=answer]
|
38 | 60 | ----
|
| 61 | +-- |
| 62 | +
|
| 63 | +二刷:: |
| 64 | ++ |
| 65 | +-- |
| 66 | +[{java_src_attr}] |
| 67 | +---- |
| 68 | +include::{sourcedir}/_0033_SearchInRotatedSortedArray_2.java[tag=answer] |
| 69 | +---- |
| 70 | +-- |
| 71 | +==== |
| 72 | + |
| 73 | +== 参考资料 |
| 74 | + |
| 75 | +. https://leetcode.cn/problems/search-in-rotated-sorted-array/solutions/5906/ji-jian-solution-by-lukelee/[33. 搜索旋转排序数组 - 极简 Solution^] |
| 76 | +. https://leetcode.cn/problems/search-in-rotated-sorted-array/solutions/220083/sou-suo-xuan-zhuan-pai-xu-shu-zu-by-leetcode-solut/[33. 搜索旋转排序数组 - 官方题解^] |
39 | 77 |
|
0 commit comments