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)/最短的桥 [shortest-bridge].html

46 lines
1.3 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>n x n</code> 的二元矩阵 <code>grid</code> ,其中 <code>1</code> 表示陆地,<code>0</code> 表示水域。</p>
<p><strong></strong> 是由四面相连的 <code>1</code> 形成的一个最大组,即不会与非组内的任何其他 <code>1</code> 相连。<code>grid</code><strong>恰好存在两座岛</strong></p>
<div class="original__bRMd">
<div>
<p>你可以将任意数量的 <code>0</code> 变为 <code>1</code> ,以使两座岛连接起来,变成 <strong>一座岛</strong></p>
<p>返回必须翻转的 <code>0</code> 的最小数目。</p>
</div>
</div>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>grid = [[0,1],[1,0]]
<strong>输出:</strong>1
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>grid = [[0,1,0],[0,0,0],[0,0,1]]
<strong>输出:</strong>2
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>grid = [[1,1,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,1],[1,1,1,1,1]]
<strong>输出:</strong>1
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == grid.length == grid[i].length</code></li>
<li><code>2 &lt;= n &lt;= 100</code></li>
<li><code>grid[i][j]</code><code>0</code><code>1</code></li>
<li><code>grid</code> 中恰有两个岛</li>
</ul>