|
1 | 1 | /**
|
2 |
| - * Description: |
3 |
| - * (This problem is an interactive problem.) |
4 |
| - * |
5 |
| - * You may recall that an array arr is a mountain array if and only if: |
6 |
| - * arr.length >= 3 |
7 |
| - * There exists some i with 0 < i < arr.length - 1 such that: |
8 |
| - * arr[0] < arr[1] < ... < arr[i - 1] < arr[i] |
9 |
| - * arr[i] > arr[i + 1] > ... > arr[arr.length - 1] |
10 |
| - * |
11 |
| - * Given a mountain array mountainArr, return the minimum index such that |
12 |
| - * mountainArr.get(index) == target. If such an index does not exist, return -1. |
13 |
| - * |
14 |
| - * You cannot access the mountain array directly. You may only access the array using |
15 |
| - * a MountainArray interface: |
16 |
| - * MountainArray.get(k) returns the element of the array at index k (0-indexed). |
17 |
| - * MountainArray.length() returns the length of the array. |
18 |
| - * |
19 |
| - * Submissions making more than 100 calls to MountainArray.get will be judged Wrong Answer. |
20 |
| - * Also, any solutions that attempt to circumvent the judge will result in disqualification. |
21 |
| - * |
22 |
| - * Ex1. |
23 |
| - * Input: array = [1,2,3,4,5,3,1], target = 3 |
24 |
| - * Output: 2 |
25 |
| - * Explanation: 3 exists in the array, at index=2 and index=5. Return the minimum index, |
26 |
| - * which is 2. |
27 |
| - * |
28 |
| - * Ex2. |
29 |
| - * Input: array = [0,1,2,4,2,1], target = 3 |
30 |
| - * Output: -1 |
31 |
| - * Explanation: 3 does not exist in the array, so we return -1. |
32 | 2 | *
|
33 | 3 | * Algorithm:
|
34 |
| - * 1. The algorithm's goal is to find the minimum index at which the value "target", |
| 4 | + * - The algorithm's goal is to find the minimum index at which the value "target", |
35 | 5 | * exist within a "MountainArray".
|
36 |
| - * 2. It employs a binary search approach, dividing the array into ascending and |
37 |
| - * descending halves.Additionally, it identifies the peak index to determine the |
| 6 | + * - It employs a binary search approach, dividing the array into ascending and |
| 7 | + * descending halves. Additionally, it identifies the peak index to determine the |
38 | 8 | * transition from ascending to descending.
|
39 | 9 | *
|
40 |
| - * Time Complexity: O(log n) |
| 10 | + * Time Complexity: O(log n) |
41 | 11 | * Space Complexity: O(1)
|
| 12 | + * |
42 | 13 | */
|
43 | 14 |
|
44 | 15 | /**
|
|
0 commit comments