# C#LeetCode刷题之#463-岛屿的周长​​​​​​​（Island Perimeter）

[[0,1,0,0],
[1,1,1,0],
[0,1,0,0],
[1,1,0,0]]

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.

[[0,1,0,0],
[1,1,1,0],
[0,1,0,0],
[1,1,0,0]]

Explanation: The perimeter is the 16 yellow stripes in the image below:

```public class Program {

public static void Main(string[] args) {
var points = new int[,] {{0, 1, 0, 0},
{1, 1, 1, 0},
{0, 1, 0, 0},
{1, 1, 0, 0}};

var res = IslandPerimeter(points);
Console.WriteLine(res);

}

public static int IslandPerimeter(int[,] grid) {
if(grid.Length == 0) return 0;
var m = grid.GetLength(0);
var n = grid.GetLength(1);
var res = 0;
for(var i = 0; i < m; ++i) {
for(var j = 0; j < n; ++j) {
if(grid[i, j] == 0) continue;
if(j == 0 || grid[i, j - 1] == 0) ++res;
if(i == 0 || grid[i - 1, j] == 0) ++res;
if(j == n - 1 || grid[i, j + 1] == 0) ++res;
if(i == m - 1 || grid[i + 1, j] == 0) ++res;
}
}
return res;
}

}```

`16`

(2)