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)/腐烂的橘子 [rotting-oranges].html
2022-03-29 12:43:11 +08:00

50 lines
1.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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>在给定的&nbsp;<code>m x n</code>&nbsp;网格<meta charset="UTF-8" />&nbsp;<code>grid</code>&nbsp;中,每个单元格可以有以下三个值之一:</p>
<ul>
<li>&nbsp;<code>0</code>&nbsp;代表空单元格;</li>
<li>&nbsp;<code>1</code>&nbsp;代表新鲜橘子;</li>
<li>&nbsp;<code>2</code>&nbsp;代表腐烂的橘子。</li>
</ul>
<p>每分钟,腐烂的橘子&nbsp;<strong>周围&nbsp;4 个方向上相邻</strong> 的新鲜橘子都会腐烂。</p>
<p>返回 <em>直到单元格中没有新鲜橘子为止所必须经过的最小分钟数。如果不可能,返回&nbsp;<code>-1</code></em>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/02/16/oranges.png" style="height: 137px; width: 650px;" /></strong></p>
<pre>
<strong>输入:</strong>grid = [[2,1,1],[1,1,0],[0,1,1]]
<strong>输出:</strong>4
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>grid = [[2,1,1],[0,1,1],[1,0,1]]
<strong>输出:</strong>-1
<strong>解释:</strong>左下角的橘子(第 2 行, 第 0 列)永远不会腐烂,因为腐烂只会发生在 4 个正向上。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>grid = [[0,2]]
<strong>输出:</strong>0
<strong>解释:</strong>因为 0 分钟时已经没有新鲜橘子了,所以答案就是 0 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>1 &lt;= m, n &lt;= 10</code></li>
<li><code>grid[i][j]</code> 仅为&nbsp;<code>0</code><code>1</code>&nbsp;&nbsp;<code>2</code></li>
</ul>