1901. Find a Peak Element II Medium

@problem@discussion
#Array#Binary Search#Matrix



1/**
2 * [1901] Find a Peak Element II
3 *
4 * A peak element in a 2D grid is an element that is strictly greater than all of its adjacent neighbors to the left, right, top, and bottom.
5 * Given a 0-indexed m x n matrix mat where no two adjacent cells are equal, find any peak element mat[i][j] and return the length 2 array [i,j].
6 * You may assume that the entire matrix is surrounded by an outer perimeter with the value -1 in each cell.
7 * You must write an algorithm that runs in O(m log(n)) or O(n log(m)) time.
8 *  
9 * Example 1:
10 * <img alt="" src="https://assets.leetcode.com/uploads/2021/06/08/1.png" style="width: 206px; height: 209px;" />
11 * 
12 * Input: mat = [[1,4],[3,2]]
13 * Output: [0,1]
14 * Explanation: Both 3 and 4 are peak elements so [1,0] and [0,1] are both acceptable answers.
15 * 
16 * Example 2:
17 * <img alt="" src="https://assets.leetcode.com/uploads/2021/06/07/3.png" style="width: 254px; height: 257px;" />
18 * 
19 * Input: mat = [[10,20,15],[21,30,14],[7,16,32]]
20 * Output: [1,1]
21 * Explanation: Both 30 and 32 are peak elements so [1,1] and [2,2] are both acceptable answers.
22 * 
23 *  
24 * Constraints:
25 * 
26 * 	m == mat.length
27 * 	n == mat[i].length
28 * 	1 <= m, n <= 500
29 * 	1 <= mat[i][j] <= 10^5
30 * 	No two adjacent cells are equal.
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/find-a-peak-element-ii/
36// discuss: https://leetcode.com/problems/find-a-peak-element-ii/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn find_peak_grid(mat: Vec<Vec<i32>>) -> Vec<i32> {
42        vec![]
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_1901() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.