forked from YaxeZhang/Just-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-peak-element.md
27 lines (18 loc) · 1.06 KB
/
find-peak-element.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
<p>A peak element is an element that is greater than its neighbors.</p>
<p>Given an input array <code>nums</code>, where <code>nums[i] ≠ nums[i+1]</code>, find a peak element and return its index.</p>
<p>The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.</p>
<p>You may imagine that <code>nums[-1] = nums[n] = -∞</code>.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> <strong>nums</strong> = <code>[1,2,3,1]</code>
<strong>Output:</strong> 2
<strong>Explanation:</strong> 3 is a peak element and your function should return the index number 2.</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> <strong>nums</strong> = <code>[</code>1,2,1,3,5,6,4]
<strong>Output:</strong> 1 or 5
<strong>Explanation:</strong> Your function can return either index number 1 where the peak element is 2,
or index number 5 where the peak element is 6.
</pre>
<p><strong>Note:</strong></p>
<p>Your solution should be in logarithmic complexity.</p>