1314. Matrix Block Sum Medium
1/**
2 * [1314] Matrix Block Sum
3 *
4 * Given a m x n matrix mat and an integer k, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for:
5 *
6 * i - k <= r <= i + k,
7 * j - k <= c <= j + k, and
8 * (r, c) is a valid position in the matrix.
9 *
10 *
11 * Example 1:
12 *
13 * Input: mat = [[1,2,3],[4,5,6],[7,8,9]], k = 1
14 * Output: [[12,21,16],[27,45,33],[24,39,28]]
15 *
16 * Example 2:
17 *
18 * Input: mat = [[1,2,3],[4,5,6],[7,8,9]], k = 2
19 * Output: [[45,45,45],[45,45,45],[45,45,45]]
20 *
21 *
22 * Constraints:
23 *
24 * m == mat.length
25 * n == mat[i].length
26 * 1 <= m, n, k <= 100
27 * 1 <= mat[i][j] <= 100
28 *
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/matrix-block-sum/
33// discuss: https://leetcode.com/problems/matrix-block-sum/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38 pub fn matrix_block_sum(mat: Vec<Vec<i32>>, k: i32) -> Vec<Vec<i32>> {
39 vec![]
40 }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_1314() {
51 }
52}
53
Back
© 2025 bowen.ge All Rights Reserved.