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 arround 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:
[[0,1,0,0], [1,1,1,0], [0,1,0,0], [1,1,0,0]] Answer: 16 Explanation: The perimeter is the 16 yellow stripes in the image below:
大概的題意,配合圖片來看,就是要多少根黃色的可以把橘色框框圍起來,那麼可以用兩層for-loop,檢驗每一個點,是0或1
若是1的話就檢查他的上下左右,先從上下的部分來看,上下必須考慮到邊界的問題,若是在邊界就必須要有一根黃色的,除了邊界外就檢查他的上或下是不是0;左右也相同
如此,就可以解決這個問題。