MCPcopy Create free account
hub / github.com/ROUTINE-STUDY/Algorithm / checkOutline

Method checkOutline

LeetCode/BFS/463. Island Perimeter/Ingyu.kt:4–16  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2 fun islandPerimeter(grid: Array<IntArray>): Int {
3 var sum = 0
4 fun checkOutline(grid:Array<IntArray>, i:Int, j:Int):Int {
5 var neighbor = 0
6 // left
7 if (0 <= j-1 && grid[i][j-1] == 1) neighbor++
8 // right
9 if (j+1 < grid[i].size && grid[i][j+1] == 1) neighbor++
10 // top
11 if (0 <= i-1 && grid[i-1][j] == 1) neighbor++
12 // bottom
13 if (i+1 <grid.size && grid[i+1][j] == 1) neighbor++
14
15 return neighbor
16 }
17
18 for (i in 0..grid.size-1) {
19 for (j in 0..grid[i].size-1) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected