Skip to content

Commit d61a022

Browse files
committed
Update 0695 solution
1 parent 1357541 commit d61a022

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

website/content/ChapterFour/0600~0699/0695.Max-Area-of-Island.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ Given the above grid, return`0`.
4545
## 代码
4646

4747
```go
48+
49+
var dir = [][]int{
50+
{-1, 0},
51+
{0, 1},
52+
{1, 0},
53+
{0, -1},
54+
}
55+
4856
func maxAreaOfIsland(grid [][]int) int {
4957
res := 0
5058
for i, row := range grid {
@@ -61,6 +69,10 @@ func maxAreaOfIsland(grid [][]int) int {
6169
return res
6270
}
6371

72+
func isInGrid(grid [][]int, x, y int) bool {
73+
return x >= 0 && x < len(grid) && y >= 0 && y < len(grid[0])
74+
}
75+
6476
func areaOfIsland(grid [][]int, x, y int) int {
6577
if !isInGrid(grid, x, y) || grid[x][y] == 0 {
6678
return 0
@@ -74,6 +86,7 @@ func areaOfIsland(grid [][]int, x, y int) int {
7486
}
7587
return total
7688
}
89+
7790
```
7891

7992

0 commit comments

Comments
 (0)