Class Solution
java.lang.Object
g0601_0700.s0695_max_area_of_island.Solution
695 - Max Area of Island.<p>Medium</p>
<p>You are given an <code>m x n</code> binary matrix <code>grid</code>. An island is a group of <code>1</code>’s (representing land) connected <strong>4-directionally</strong> (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.</p>
<p>The <strong>area</strong> of an island is the number of cells with a value <code>1</code> in the island.</p>
<p>Return <em>the maximum <strong>area</strong> of an island in</em> <code>grid</code>. If there is no island, return <code>0</code>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/05/01/maxarea1-grid.jpg" alt="" /></p>
<p><strong>Input:</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]]</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong> The answer is not 11, because the island must be connected 4-directionally.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> grid = [[0,0,0,0,0,0,0,0]]</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Constraints:</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]</code> is either <code>0</code> or <code>1</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxAreaOfIsland
public int maxAreaOfIsland(int[][] grid)
-