|
| 1 | +# [1901. Find a Peak Element II](https://leetcode-cn.com/problems/find-a-peak-element-ii) |
| 2 | + |
| 3 | +[English Version](/solution/1900-1999/1901.Find%20a%20Peak%20Element%20II/README_EN.md) |
| 4 | + |
| 5 | +## 题目描述 |
| 6 | + |
| 7 | +<!-- 这里写题目描述 --> |
| 8 | + |
| 9 | +<p>A <strong>peak</strong> element in a 2D grid is an element that is <strong>strictly greater</strong> than all of its <strong>adjacent </strong>neighbors to the left, right, top, and bottom.</p> |
| 10 | + |
| 11 | +<p>Given a <strong>0-indexed</strong> <code>m x n</code> matrix <code>mat</code> where <strong>no two adjacent cells are equal</strong>, find <strong>any</strong> peak element <code>mat[i][j]</code> and return <em>the length 2 array </em><code>[i,j]</code>.</p> |
| 12 | + |
| 13 | +<p>You may assume that the entire matrix is surrounded by an <strong>outer perimeter</strong> with the value <code>-1</code> in each cell.</p> |
| 14 | + |
| 15 | +<p>You must write an algorithm that runs in <code>O(m log(n))</code> or <code>O(n log(m))</code> time.</p> |
| 16 | + |
| 17 | +<p> </p> |
| 18 | +<p><strong>Example 1:</strong></p> |
| 19 | + |
| 20 | +<p><img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1901.Find%20a%20Peak%20Element%20II/images/1.png" style="width: 206px; height: 209px;" /></p> |
| 21 | + |
| 22 | +<pre> |
| 23 | +<strong>Input:</strong> mat = [[1,4],[3,2]] |
| 24 | +<strong>Output:</strong> [0,1] |
| 25 | +<strong>Explanation:</strong> Both 3 and 4 are peak elements so [1,0] and [0,1] are both acceptable answers. |
| 26 | +</pre> |
| 27 | + |
| 28 | +<p><strong>Example 2:</strong></p> |
| 29 | + |
| 30 | +<p><strong><img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1901.Find%20a%20Peak%20Element%20II/images/3.png" style="width: 254px; height: 257px;" /></strong></p> |
| 31 | + |
| 32 | +<pre> |
| 33 | +<strong>Input:</strong> mat = [[10,20,15],[21,30,14],[7,16,32]] |
| 34 | +<strong>Output:</strong> [1,1] |
| 35 | +<strong>Explanation:</strong> Both 30 and 32 are peak elements so [1,1] and [2,2] are both acceptable answers. |
| 36 | +</pre> |
| 37 | + |
| 38 | +<p> </p> |
| 39 | +<p><strong>Constraints:</strong></p> |
| 40 | + |
| 41 | +<ul> |
| 42 | + <li><code>m == mat.length</code></li> |
| 43 | + <li><code>n == mat[i].length</code></li> |
| 44 | + <li><code>1 <= m, n <= 500</code></li> |
| 45 | + <li><code>1 <= mat[i][j] <= 10<sup>5</sup></code></li> |
| 46 | + <li>No two adjacent cells are equal.</li> |
| 47 | +</ul> |
| 48 | + |
| 49 | + |
| 50 | +## 解法 |
| 51 | + |
| 52 | +<!-- 这里可写通用的实现逻辑 --> |
| 53 | + |
| 54 | +<!-- tabs:start --> |
| 55 | + |
| 56 | +### **Python3** |
| 57 | + |
| 58 | +<!-- 这里可写当前语言的特殊实现逻辑 --> |
| 59 | + |
| 60 | +```python |
| 61 | + |
| 62 | +``` |
| 63 | + |
| 64 | +### **Java** |
| 65 | + |
| 66 | +<!-- 这里可写当前语言的特殊实现逻辑 --> |
| 67 | + |
| 68 | +```java |
| 69 | + |
| 70 | +``` |
| 71 | + |
| 72 | +### **...** |
| 73 | + |
| 74 | +``` |
| 75 | +
|
| 76 | +``` |
| 77 | + |
| 78 | +<!-- tabs:end --> |
0 commit comments