mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-08-02 10:30:37 +08:00
规范格式
This commit is contained in:
24
leetcode/0463.Island-Perimeter/463. Island Perimeter.go
Normal file
24
leetcode/0463.Island-Perimeter/463. Island Perimeter.go
Normal file
@ -0,0 +1,24 @@
|
||||
package leetcode
|
||||
|
||||
func islandPerimeter(grid [][]int) int {
|
||||
counter := 0
|
||||
for i := 0; i < len(grid); i++ {
|
||||
for j := 0; j < len(grid[0]); j++ {
|
||||
if grid[i][j] == 1 {
|
||||
if i-1 < 0 || grid[i-1][j] == 0 {
|
||||
counter++
|
||||
}
|
||||
if i+1 >= len(grid) || grid[i+1][j] == 0 {
|
||||
counter++
|
||||
}
|
||||
if j-1 < 0 || grid[i][j-1] == 0 {
|
||||
counter++
|
||||
}
|
||||
if j+1 >= len(grid[0]) || grid[i][j+1] == 0 {
|
||||
counter++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return counter
|
||||
}
|
Reference in New Issue
Block a user