Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def islandPerimeter(self, grid: List[List[int]]) -> int:
- W = len(grid)
- H = len(grid[0])
- def is_water(x: int, y: int) -> bool:
- return not (
- 0 <= x < W and
- 0 <= y < H and
- grid[x][y] == 1
- )
- ans = 0
- for x in range(W):
- for y in range(H):
- if is_water(x, y):
- continue
- for dx, dy in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
- if is_water(x + dx, y + dy):
- ans += 1
- return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement