Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

463. 岛屿的周长 #13

Open
mentaLwz opened this issue Oct 30, 2020 · 0 comments
Open

463. 岛屿的周长 #13

mentaLwz opened this issue Oct 30, 2020 · 0 comments
Labels
Leetcode2020 2020含泪刷的题

Comments

@mentaLwz
Copy link
Owner

class Solution:
    def islandPerimeter(self, grid: List[List[int]]) -> int:

        length = 0
        for i, e in enumerate(grid):
            for j, f in enumerate(grid[i]):
                curl = 0
                if grid[i][j]:
                    
                    if i -1 >= 0:
                        if grid[i-1][j]:
                            pass
                        else:
                            curl += 1
                    else:
                        curl += 1
                    if i + 1 < len(grid):
                        if grid[i + 1][j]:
                            pass
                        else:
                            curl += 1
                    else:
                        curl += 1
                    if j - 1 >= 0:
                        if grid[i][j - 1]:
                            pass
                        else:
                            curl += 1
                    else:
                        curl += 1
                    if j + 1 < len(e):
                        if grid[i][j + 1]:
                            pass
                        else:
                            curl += 1
                    else:
                        curl += 1
                length += curl
        return length
@mentaLwz mentaLwz added the Leetcode2020 2020含泪刷的题 label Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Leetcode2020 2020含泪刷的题
Projects
None yet
Development

No branches or pull requests

1 participant