1 Star 41 Fork 18

小墨/力扣题库(完整版)

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
01 矩阵 [2bCMpM].html 1.40 KB
Copy Edit Raw Blame History
小墨 authored 2025-09-29 14:43 +08:00 . update
<p>给定一个由 <code>0</code><code>1</code> 组成的矩阵 <code>mat</code>&nbsp;,请输出一个大小相同的矩阵,其中每一个格子是 <code>mat</code> 中对应位置元素到最近的 <code>0</code> 的距离。</p>
<p>两个相邻元素间的距离为 <code>1</code></p>
<p>&nbsp;</p>
<p><b>示例 1:</b></p>
<p><img alt="" src="https://pic.leetcode-cn.com/1626667201-NCWmuP-image.png" style="width: 150px; " /></p>
<pre>
<strong>输入:</strong>mat =<strong> </strong>[[0,0,0],[0,1,0],[0,0,0]]
<strong>输出:</strong>[[0,0,0],[0,1,0],[0,0,0]]
</pre>
<p><b>示例 2:</b></p>
<p><img alt="" src="https://pic.leetcode-cn.com/1626667205-xFxIeK-image.png" style="width: 150px; " /></p>
<pre>
<strong>输入:</strong>mat =<b> </b>[[0,0,0],[0,1,0],[1,1,1]]
<strong>输出:</strong>[[0,0,0],[0,1,0],[1,2,1]]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == mat.length</code></li>
<li><code>n == mat[i].length</code></li>
<li><code>1 &lt;= m, n &lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= m * n &lt;= 10<sup>4</sup></code></li>
<li><code>mat[i][j] is either 0 or 1.</code></li>
<li><code>mat</code> 中至少有一个 <code>0&nbsp;</code></li>
</ul>
<p>&nbsp;</p>
<p><meta charset="UTF-8" />注意:本题与主站 542&nbsp;题相同:<a href="https://leetcode-cn.com/problems/01-matrix/">https://leetcode-cn.com/problems/01-matrix/</a></p>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/coder-xiaomo/leetcode-problemset.git
git@gitee.com:coder-xiaomo/leetcode-problemset.git
coder-xiaomo
leetcode-problemset
力扣题库(完整版)
master

Search