1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/矩阵区域和 [matrix-block-sum].html
2022-03-29 12:43:11 +08:00

35 lines
1013 B
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个 <code>m x n</code> 的矩阵 <code>mat</code> 和一个整数 <code>k</code> ,请你返回一个矩阵 <code>answer</code> ,其中每个 <code>answer[i][j]</code> 是所有满足下述条件的元素 <code>mat[r][c]</code> 的和: </p>
<ul>
<li><code>i - k <= r <= i + k, </code></li>
<li><code>j - k <= c <= j + k</code></li>
<li><code>(r, c)</code> 在矩阵内。</li>
</ul>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>mat = [[1,2,3],[4,5,6],[7,8,9]], k = 1
<strong>输出:</strong>[[12,21,16],[27,45,33],[24,39,28]]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>mat = [[1,2,3],[4,5,6],[7,8,9]], k = 2
<strong>输出:</strong>[[45,45,45],[45,45,45],[45,45,45]]
</pre>
<p> </p>
<p><strong>提示:</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>