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)/使陆地分离的最少天数 [minimum-number-of-days-to-disconnect-island].html

37 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>给你一个大小为 <code>m x n</code> ,由若干 <code>0</code><code>1</code> 组成的二维网格 <code>grid</code> ,其中 <code>1</code> 表示陆地, <code>0</code> 表示水。<strong>岛屿</strong> 由水平方向或竖直方向上相邻的 <code>1</code> (陆地)连接形成。</p>
<p>如果 <strong>恰好只有一座岛屿 </strong>,则认为陆地是 <strong>连通的</strong> ;否则,陆地就是 <strong>分离的</strong></p>
<p>一天内,可以将 <strong>任何单个</strong> 陆地单元(<code>1</code>)更改为水单元(<code>0</code>)。</p>
<p>返回使陆地分离的最少天数。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/12/24/land1.jpg" style="width: 500px; height: 169px;" />
<pre>
<strong>输入:</strong>grid = [[0,1,1,0],[0,1,1,0],[0,0,0,0]]
<strong>输出:</strong>2
<strong>解释:</strong>至少需要 2 天才能得到分离的陆地。
将陆地 grid[1][1] 和 grid[0][2] 更改为水,得到两个分离的岛屿。</pre>
<p><strong class="example">示例 2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/12/24/land2.jpg" style="width: 404px; height: 85px;" />
<pre>
<strong>输入:</strong>grid = [[1,1]]
<strong>输出:</strong>2
<strong>解释:</strong>如果网格中都是水,也认为是分离的 ([[1,1]] -&gt; [[0,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;= 30</code></li>
<li><code>grid[i][j]</code><code>0</code><code>1</code></li>
</ul>