Max Area of Island
Problem statement
Given a rectangular binary matrix grid, return the maximum area of an island.
An island is a maximal group of 1 cells connected horizontally or vertically. Its area is its number of cells. Return 0 when the grid contains no land.
Function
maxAreaOfIsland(grid: int[][]) → intExamples
Example 1
grid = [[0,0,1,0],[1,1,1,0],[0,1,0,1]]return = 5The center island has five cells; the bottom-right cell is a separate area-1 island.
Example 2
grid = [[0,0],[0,0]]return = 0The matrix has no land.
Example 3
grid = [[1]]return = 1The only cell forms an island of area 1.
Constraints
1 <= grid.length, grid[i].length <= 300.- Every row has the same length.
- Every cell is
0or1.