mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
38 lines
1.8 KiB
HTML
38 lines
1.8 KiB
HTML
<p>给定一个由 <code>0</code> 和 <code>1</code> 组成的非空二维数组 <code>grid</code> ,用来表示海洋岛屿地图。</p>
|
|
|
|
<p>一个 <strong>岛屿</strong> 是由一些相邻的 <code>1</code> (代表土地) 构成的组合,这里的「相邻」要求两个 <code>1</code> 必须在水平或者竖直方向上相邻。你可以假设 <code>grid</code> 的四个边缘都被 <code>0</code>(代表水)包围着。</p>
|
|
|
|
<p>找到给定的二维数组中最大的岛屿面积。如果没有岛屿,则返回面积为 <code>0</code> 。</p>
|
|
|
|
<p> </p>
|
|
|
|
<p><strong>示例 1:</strong></p>
|
|
|
|
<p><img alt="" src="https://pic.leetcode-cn.com/1626667010-nSGPXz-image.png" style="width: 452px; " /></p>
|
|
|
|
<pre>
|
|
<strong>输入: </strong>grid = [[0,0,1,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,1,1,0,1,0,0,0,0,0,0,0,0],[0,1,0,0,1,1,0,0,1,0,1,0,0],[0,1,0,0,1,1,0,0,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,0,1,1,0,0,0,0]]
|
|
<strong>输出: </strong>6
|
|
<strong>解释: </strong>对于上面这个给定矩阵应返回 <code>6</code>。注意答案不应该是 <code>11</code> ,因为岛屿只能包含水平或垂直的四个方向的 <code>1</code> 。</pre>
|
|
|
|
<p><strong>示例 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>输入: </strong>grid = [[0,0,0,0,0,0,0,0]]
|
|
<strong>输出: </strong>0</pre>
|
|
|
|
<p> </p>
|
|
|
|
<p><strong>提示:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>m == grid.length</code></li>
|
|
<li><code>n == grid[i].length</code></li>
|
|
<li><code>1 <= m, n <= 50</code></li>
|
|
<li><code>grid[i][j] is either 0 or 1</code></li>
|
|
</ul>
|
|
|
|
<p> </p>
|
|
|
|
<p>注意:本题与主站 695 题相同: <a href="https://leetcode-cn.com/problems/max-area-of-island/">https://leetcode-cn.com/problems/max-area-of-island/</a></p>
|