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)/统计封闭岛屿的数目 [number-of-closed-islands].html
2022-03-29 12:43:11 +08:00

47 lines
1.6 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>grid</code>&nbsp;<code>0</code>&nbsp;(土地)和 <code>1</code>&nbsp;组成。岛是由最大的4个方向连通的 <code>0</code>&nbsp;组成的群,封闭岛是一个&nbsp;<code>完全</code> 由1包围左、上、右、下的岛。</p>
<p>请返回 <em>封闭岛屿</em> 的数目。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/10/31/sample_3_1610.png" style="height: 151px; width: 240px;" /></p>
<pre>
<strong>输入:</strong>grid = [[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,1,0],[1,0,0,0,0,1,0,1],[1,1,1,1,1,1,1,0]]
<strong>输出:</strong>2
<strong>解释:</strong>
灰色区域的岛屿是封闭岛屿,因为这座岛屿完全被水域包围(即被 1 区域包围)。</pre>
<p><strong>示例 2</strong></p>
<p><img src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/11/07/sample_4_1610.png" style="height: 98px; width: 160px;" /></p>
<pre>
<strong>输入:</strong>grid = [[0,0,1,0,0],[0,1,0,1,0],[0,1,1,1,0]]
<strong>输出:</strong>1
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>grid = [[1,1,1,1,1,1,1],
&nbsp; [1,0,0,0,0,0,1],
&nbsp; [1,0,1,1,1,0,1],
&nbsp; [1,0,1,0,1,0,1],
&nbsp; [1,0,1,1,1,0,1],
&nbsp; [1,0,0,0,0,0,1],
[1,1,1,1,1,1,1]]
<strong>输出:</strong>2
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= grid.length, grid[0].length &lt;= 100</code></li>
<li><code>0 &lt;= grid[i][j] &lt;=1</code></li>
</ul>