-
Notifications
You must be signed in to change notification settings - Fork 160
/
peak-index-in-a-mountain-array.md
31 lines (23 loc) · 1.14 KB
/
peak-index-in-a-mountain-array.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<p>Let's call an array <code>A</code> a <em>mountain</em> if the following properties hold:</p>
<ul>
<li><code>A.length >= 3</code></li>
<li>There exists some <code>0 < i < A.length - 1</code> such that <code>A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1]</code></li>
</ul>
<p>Given an array that is definitely a mountain, return any <code>i</code> such that <code>A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1]</code>.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong><span id="example-input-1-1">[0,1,0]</span>
<strong>Output: </strong><span id="example-output-1">1</span>
</pre>
<div>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong><span id="example-input-2-1">[0,2,1,0]</span>
<strong>Output: </strong><span id="example-output-2">1</span></pre>
</div>
<p><strong>Note:</strong></p>
<ol>
<li><code>3 <= A.length <= 10000</code></li>
<li><code><font face="monospace">0 <= A[i] <= 10^6</font></code></li>
<li>A is a mountain, as defined above.</li>
</ol>