MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / getLiveNeighbors

Function getLiveNeighbors

game_of_life_289/solution.go:31–48  ·  view source on GitHub ↗
(board [][]int, r, c, rows, cols int)

Source from the content-addressed store, hash-verified

29}
30
31func getLiveNeighbors(board [][]int, r, c, rows, cols int) int {
32 cnt := 0
33 for cRow := r - 1; cRow <= r+1; cRow++ {
34 if cRow > -1 && cRow < rows {
35 for cCol := c - 1; cCol <= c+1; cCol++ {
36 if cCol > -1 && cCol < cols {
37 if (cCol != c || cRow != r) &&
38 // Remember that previously live and going to die cells are -1
39 (board[cRow][cCol] == -1 || board[cRow][cCol] == 1) {
40 cnt++
41 }
42 }
43 }
44 }
45 }
46
47 return cnt
48}

Callers 1

gameOfLifeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected