Island Perimeter 周长

Island Perimeter 周长_第1张图片


Island Perimeter 周长_第2张图片

What a great idea! The reason why we only count the right and down neighbors is that if

one cell has a left or up neighbor, it must have been counted by other cells as their right or down neighbors, and in the end, we just decrease the two sides of those adjacent islands.


Island Perimeter 周长_第3张图片

你可能感兴趣的:(Island Perimeter 周长)