Skip to content

Commit

Permalink
0463.岛屿的周长增加go解法
Browse files Browse the repository at this point in the history
0463.岛屿的周长增加go解法
  • Loading branch information
PanYuHaa authored Sep 3, 2022
1 parent 697b8ac commit a605d75
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions problems/0463.岛屿的周长.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ class Solution:
```

Go:
```go
func islandPerimeter(grid [][]int) int {
m, n := len(grid), len(grid[0])
res := 0
for i := 0; i < m; i++ {
for j := 0; j < n; j++ {
if grid[i][j] == 1 {
res += 4
// 上下左右四个方向
if i > 0 && grid[i-1][j] == 1 {res--} // 上边有岛屿
if i < m-1 && grid[i+1][j] == 1 {res--} // 下边有岛屿
if j > 0 && grid[i][j-1] == 1 {res--} // 左边有岛屿
if j < n-1 && grid[i][j+1] == 1 {res--} // 右边有岛屿
}
}
}
return res
}
```

JavaScript:
```javascript
Expand Down

0 comments on commit a605d75

Please sign in to comment.