Skip to content

Commit 3649f06

Browse files
committed
Runtime: 101 ms (Top 32.25%) | Memory: 42 MB (Top 79.17%)
1 parent 99cc174 commit 3649f06

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
// Runtime: 101 ms (Top 32.25%) | Memory: 42 MB (Top 79.17%)
12
/**
23
* @param {number[][]} board
34
* @return {void} Do not return anything, modify board in-place instead.
45
*/
56
var gameOfLife = function(board) {
67
const m = board.length, n = board[0].length;
78
let copy = JSON.parse(JSON.stringify(board));
8-
9+
910
const getNeighbor = (row, col) => {
1011
let radius = [-1, 0, 1], count = 0;
1112
for(let i = 0; i < 3; i++) {
@@ -16,17 +17,17 @@ var gameOfLife = function(board) {
1617
count++;
1718
}
1819
}
19-
}
20+
}
2021
}
2122
return count;
2223
}
23-
24+
2425
for(let i = 0; i < m; i++) {
2526
for(let j = 0; j < n; j++) {
2627
const count = getNeighbor(i, j);
2728
if(copy[i][j] == 1) {
2829
if(count < 2 || count > 3) {
29-
board[i][j] = 0;
30+
board[i][j] = 0;
3031
}
3132
} else {
3233
if(count == 3) {
@@ -35,4 +36,4 @@ var gameOfLife = function(board) {
3536
}
3637
}
3738
}
38-
};
39+
};

0 commit comments

Comments
 (0)