2373. Largest Local Values in a Matrix Easy
1/**
2 * [2373] Largest Local Values in a Matrix
3 *
4 * You are given an n x n integer matrix grid.
5 * Generate an integer matrix maxLocal of size (n - 2) x (n - 2) such that:
6 *
7 * maxLocal[i][j] is equal to the largest value of the 3 x 3 matrix in grid centered around row i + 1 and column j + 1.
8 *
9 * In other words, we want to find the largest value in every contiguous 3 x 3 matrix in grid.
10 * Return the generated matrix.
11 *
12 * Example 1:
13 * <img alt="" src="https://assets.leetcode.com/uploads/2022/06/21/ex1.png" style="width: 371px; height: 210px;" />
14 * Input: grid = [[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]
15 * Output: [[9,9],[8,6]]
16 * Explanation: The diagram above shows the original matrix and the generated matrix.
17 * Notice that each value in the generated matrix corresponds to the largest value of a contiguous 3 x 3 matrix in grid.
18 * Example 2:
19 * <img alt="" src="https://assets.leetcode.com/uploads/2022/07/02/ex2new2.png" style="width: 436px; height: 240px;" />
20 * Input: grid = [[1,1,1,1,1],[1,1,1,1,1],[1,1,2,1,1],[1,1,1,1,1],[1,1,1,1,1]]
21 * Output: [[2,2,2],[2,2,2],[2,2,2]]
22 * Explanation: Notice that the 2 is contained within every contiguous 3 x 3 matrix in grid.
23 *
24 *
25 * Constraints:
26 *
27 * n == grid.length == grid[i].length
28 * 3 <= n <= 100
29 * 1 <= grid[i][j] <= 100
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/largest-local-values-in-a-matrix/
35// discuss: https://leetcode.com/problems/largest-local-values-in-a-matrix/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn largest_local(grid: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
41 vec![]
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_2373() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.