Given a non-empty 2D array grid of 0 ' and 1 ' s, an island was a group of 1 ' s (representing land) connected 4- directionally (horizontal or vertical.) Assume all four edges of the grid is surrounded by water.
Find the maximum area of a in the given 2D array. (If There is no island, the maximum area is 0.)
Example 1:
[[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]]
Given the above grid, return 6 . Note The answer is not one, because the must be connected 4-directionally.
Example 2:
[[0,0,0,0,0,0,0,0]]
Given the above grid, return 0 .
Note: The length of each dimension in the given grid does is not exceed 50.
Iterate through the array to find the area of each island, 22 as a ratio, and return the maximum value.