From d61a0226b8f4f3d4e29aabfde35e23936259feeb Mon Sep 17 00:00:00 2001 From: YDZ Date: Wed, 2 Jun 2021 07:09:59 +0800 Subject: [PATCH] Update 0695 solution --- .../0600~0699/0695.Max-Area-of-Island.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/website/content/ChapterFour/0600~0699/0695.Max-Area-of-Island.md b/website/content/ChapterFour/0600~0699/0695.Max-Area-of-Island.md index 7ea96495..05c391e0 100644 --- a/website/content/ChapterFour/0600~0699/0695.Max-Area-of-Island.md +++ b/website/content/ChapterFour/0600~0699/0695.Max-Area-of-Island.md @@ -45,6 +45,14 @@ Given the above grid, return`0`. ## 代码 ```go + +var dir = [][]int{ + {-1, 0}, + {0, 1}, + {1, 0}, + {0, -1}, +} + func maxAreaOfIsland(grid [][]int) int { res := 0 for i, row := range grid { @@ -61,6 +69,10 @@ func maxAreaOfIsland(grid [][]int) int { return res } +func isInGrid(grid [][]int, x, y int) bool { + return x >= 0 && x < len(grid) && y >= 0 && y < len(grid[0]) +} + func areaOfIsland(grid [][]int, x, y int) int { if !isInGrid(grid, x, y) || grid[x][y] == 0 { return 0 @@ -74,6 +86,7 @@ func areaOfIsland(grid [][]int, x, y int) int { } return total } + ```