Class Solution
java.lang.Object
g0801_0900.s0852_peak_index_in_a_mountain_array.Solution
852 - Peak Index in a Mountain Array.<p>Easy</p>
<p>Let’s call an array <code>arr</code> a <strong>mountain</strong> if the following properties hold:</p>
<ul>
<li><code>arr.length >= 3</code></li>
<li>There exists some <code>i</code> with <code>0 < i < arr.length - 1</code> such that:
<ul>
<li><code>arr[0] < arr[1] < ... arr[i-1] < arr[i]</code></li>
<li><code>arr[i] > arr[i+1] > ... > arr[arr.length - 1]</code></li>
</ul>
</li>
</ul>
<p>Given an integer array <code>arr</code> that is <strong>guaranteed</strong> to be a mountain, return any <code>i</code> such that <code>arr[0] < arr[1] < ... arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1]</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> arr = [0,1,0]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> arr = [0,2,1,0]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> arr = [0,10,5,2]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 <= arr.length <= 10<sup>4</sup></code></li>
<li><code>0 <= arr[i] <= 10<sup>6</sup></code></li>
<li><code>arr</code> is <strong>guaranteed</strong> to be a mountain array.</li>
</ul>
<p><strong>Follow up:</strong> Finding the <code>O(n)</code> is straightforward, could you find an <code>O(log(n))</code> solution?</p>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
peakIndexInMountainArray
public int peakIndexInMountainArray(int[] arr)
-