mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2026-03-13 10:02:05 +08:00
Update 0695 solution
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user