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)/使陆地分离的最少天数 [minimum-number-of-days-to-disconnect-island].html
2022-03-29 12:43:11 +08:00

60 lines
2.0 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>0</code><code>1</code> 组成的二维网格 <code>grid</code> ,其中 <code>0</code> 表示水,而 <code>1</code> 表示陆地。岛屿由水平方向或竖直方向上相邻的 <code>1</code> (陆地)连接形成。</p>
<p>如果 <strong>恰好只有一座岛屿 </strong>,则认为陆地是 <strong>连通的</strong> ;否则,陆地就是 <strong>分离的</strong></p>
<p>一天内,可以将任何单个陆地单元(<code>1</code>)更改为水单元(<code>0</code>)。</p>
<p>返回使陆地分离的最少天数。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/08/30/1926_island.png" style="height: 139px; width: 498px;"></strong></p>
<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>示例 2</strong></p>
<pre><strong>输入:</strong>grid = [[1,1]]
<strong>输出:</strong>2
<strong>解释:</strong>如果网格中都是水,也认为是分离的 ([[1,1]] -&gt; [[0,0]])0 岛屿。
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>grid = [[1,0,1,0]]
<strong>输出:</strong>0
</pre>
<p><strong>示例 4</strong></p>
<pre><strong>输入:</strong>grid = [[1,1,0,1,1],
&nbsp; [1,1,1,1,1],
&nbsp; [1,1,0,1,1],
&nbsp; [1,1,0,1,1]]
<strong>输出:</strong>1
</pre>
<p><strong>示例 5</strong></p>
<pre><strong>输入:</strong>grid = [[1,1,0,1,1],
&nbsp; [1,1,1,1,1],
&nbsp; [1,1,0,1,1],
&nbsp; [1,1,1,1,1]]
<strong>输出:</strong>2
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= grid.length, grid[i].length &lt;= 30</code></li>
<li><code>grid[i][j]</code><code>0</code><code>1</code></li>
</ul>