1 Star 0 Fork 18

busfly/力扣题库(完整版)

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
matrix-block-sum.html 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
小墨 提交于 2022-03-29 12:55 +08:00 . update
<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 &lt;= r &lt;= i + k,</code></li>
<li><code>j - k &lt;= c &lt;= j + k</code>, and</li>
<li><code>(r, c)</code> is a valid position in the matrix.</li>
</ul>
<p>&nbsp;</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>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>m ==&nbsp;mat.length</code></li>
<li><code>n ==&nbsp;mat[i].length</code></li>
<li><code>1 &lt;= m, n, k &lt;= 100</code></li>
<li><code>1 &lt;= mat[i][j] &lt;= 100</code></li>
</ul>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/busfly/leetcode-problemset.git
git@gitee.com:busfly/leetcode-problemset.git
busfly
leetcode-problemset
力扣题库(完整版)
master

搜索帮助