my python


  • 0
    H
    class Solution(object):
        def islandPerimeter(self, grid):
            """
            :type grid: List[List[int]]
            :rtype: int
            """
            total = 0
            for tot in grid:
                total += sum(tot)
            row = len(grid)
            col = len(grid[0])
            dup = 0
            for i in range(row):
                for j in range(col):
                    if i+1 <row:
                        if grid[i][j]+grid[i+1][j]==2:
                            dup += 1
                    if j+1 < col:
                        if grid[i][j]+grid[i][j+1]==2:
                           dup += 1
            return total*4-dup*2
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.