Python Scan Solution


  • 0
    class Solution(object):
        def islandPerimeter(self, grid):
            ans = 0
            for i in range(len(grid)):
                for j in range(len(grid[0])):
                    if grid[i][j] == 1:
                        ans += 4
                        if i < len(grid)-1 and grid[i+1][j] == 1:
                            ans -= 2
                        if j < len(grid[0])-1 and grid[i][j+1] == 1:
                            ans -= 2
            return ans

Log in to reply
 

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