Leetcode - Arrays | Island
463. Island Perimeter[E]
https://leetcode.com/problems/island-perimeter/
Description
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water.
Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).
The island doesn’t have “lakes” (water inside that isn’t connected to the water around the island). One cell is a square with side length 1. The grid is rectangular, width and height don’t exceed 100. Determine the perimeter of the island.
Example:
1 | Input: |
Solution
1 |
695. Max Area of Island[M]
https://leetcode.com/problems/max-area-of-island/
Description
Given a non-empty 2D array grid of 0’s and 1’s, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.
Find the maximum area of an island in the given 2D array. (If there is no island, the maximum area is 0.)
Example 1:
1 | [[0,0,1,0,0,0,0,1,0,0,0,0,0], |
Given the above grid, return 6. Note the answer is not 11, because the island must be connected 4-directionally.
Example 2:
1 | [[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 not exceed 50.
Solution
200. Number of Islands[M]
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/
Description
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
Example 1:
1 | Input: grid = [ |
Example 2:
1 | Input: grid = [ |
Solution
1 |





