leetcode463. Island Perimeter
You are given row x col
grid
representing a map where grid[i][j] = 1
represents land and grid[i][j] = 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", meaning the water inside 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: grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]Output: 16Explanation: The perimeter is the 16 yellow stripes in the image above.
Example 2:
Input: grid = [[1]]Output: 4
Example 3:
Input: grid = [[1,0]]Output: 4
如果这个位置上是1,那么加4,当出现相邻的时候,则需要减去2,所以遍历左边跟上边的所有情况,因为右边跟下边会在后面i++,j++的时候遍历到;
Runtime: 4 ms, faster than 100.00% of Java online submissions for Island Perimeter.
Memory Usage: 42.9 MB, less than 80.05% of Java online submissions for Island Perimeter.