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

35 lines
1013 B
HTML
Raw Normal View History

2022-03-27 20:37:52 +08:00
<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>