mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
33 lines
1.0 KiB
HTML
33 lines
1.0 KiB
HTML
<p>Given a <code>m x n</code> matrix <code>mat</code> and an integer <code>k</code>, return <em>a matrix</em> <code>answer</code> <em>where each</em> <code>answer[i][j]</code> <em>is the sum of all elements</em> <code>mat[r][c]</code> <em>for</em>:</p>
|
|
|
|
<ul>
|
|
<li><code>i - k <= r <= i + k,</code></li>
|
|
<li><code>j - k <= c <= j + k</code>, and</li>
|
|
<li><code>(r, c)</code> is a valid position in the matrix.</li>
|
|
</ul>
|
|
|
|
<p> </p>
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> mat = [[1,2,3],[4,5,6],[7,8,9]], k = 1
|
|
<strong>Output:</strong> [[12,21,16],[27,45,33],[24,39,28]]
|
|
</pre>
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> mat = [[1,2,3],[4,5,6],[7,8,9]], k = 2
|
|
<strong>Output:</strong> [[45,45,45],[45,45,45],[45,45,45]]
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>m == mat.length</code></li>
|
|
<li><code>n == mat[i].length</code></li>
|
|
<li><code>1 <= m, n, k <= 100</code></li>
|
|
<li><code>1 <= mat[i][j] <= 100</code></li>
|
|
</ul>
|