|
3 | 3 | * Search in Rotated Sorted Array
|
4 | 4 | **
|
5 | 5 | * There is an integer array nums sorted in ascending order (with distinct values).
|
6 |
| - * |
7 |
| - * Prior to being passed to your function, nums is possibly rotated at an unknown pivot index k (1 <= k < nums.length) |
8 |
| - * such that the resulting array is |
9 |
| - * [nums[k], nums[k+1], ..., nums[n-1], |
10 |
| - * nums[0], nums[1], ..., nums[k-1]] (0-indexed). |
11 |
| - * |
| 6 | + * Prior to being passed to your function, |
| 7 | + * nums is possibly rotated at an unknown pivot index k (1 <= k < nums.length) |
| 8 | + * such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] (0-indexed). |
12 | 9 | * For example, [0,1,2,4,5,6,7] might be rotated at pivot index 3 and become [4,5,6,7,0,1,2].
|
13 | 10 | *
|
14 | 11 | * Given the array nums after the possible rotation and an integer target,
|
15 | 12 | * return the index of target if it is in nums, or -1 if it is not in nums.
|
16 | 13 | *
|
17 | 14 | * You must write an algorithm with O(log n) runtime complexity.
|
| 15 | + * |
| 16 | + * Example 1: |
| 17 | + * Input: nums = [4,5,6,7,0,1,2], target = 0 |
| 18 | + * Output: 4 |
| 19 | + * |
| 20 | + * Example 2: |
| 21 | + * Input: nums = [4,5,6,7,0,1,2], target = 3 |
| 22 | + * Output: -1 |
| 23 | + * |
| 24 | + * Example 3: |
| 25 | + * Input: nums = [1], target = 0 |
| 26 | + * Output: -1 |
| 27 | + * |
| 28 | + * Constraints: |
| 29 | + * • 1 <= nums.length <= 5000 |
| 30 | + * • -10^4 <= nums[i] <= 10^4 |
| 31 | + * • All values of nums are unique. |
| 32 | + * • nums is an ascending array that is possibly rotated. |
| 33 | + * • -10^4 <= target <= 10^4 |
18 | 34 | **
|
19 | 35 | * https://leetcode.com/problems/search-in-rotated-sorted-array/
|
20 | 36 | ***/
|
|
0 commit comments