题目:
题解:
class Solution:
def islandPerimeter(self, grid: List[List[int]]) -> int:
row=len(grid)
col=len(grid[0])
nums=0
c=0
grid=grid+[[0]*col]
for i in range(row):
grid[i].append(0)
for j in range(col):
if grid[i][j]==1:
nums+=1
if grid[i][j]==1 and grid[i+1][j]==1:
c-=2
if grid[i][j]==1 and grid[i][j+1]==1:
c-=2
c+=nums*4
return c