Island Perimeter

You are given a grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. The grid is surrounded by water and contains exactly one island, which is a group of connected land cells. The island doesn't have lakes, meaning the water inside isn't connected to the water around the island. Each cell is a 1x1 square. Determine the perimeter of the island.

Constraints

  • row == grid.length
  • col == grid[i].length
  • 1 <= row, col <= 100
  • grid[i][j] is 0 or 1
  • There is exactly one island in grid
Saving… · 2 lines
class Solution:
def islandPerimeter(self, grid: List[List[int]]) -> int:
Console

Click Run to execute sample tests.