Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaf81a75

Browse files
committed
update: 289
1 parent5a587be commitaf81a75

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
8383
|274|[H-Index](https://leetcode.com/problems/h-index/)|[JavaScript](./src/h-index/res.js)|Medium|
8484
|275|[H-Index II](https://leetcode.com/problems/h-index-ii/)|[JavaScript](./src/h-index-ii/res.js)|Medium|
8585
|287|[Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number/)|[JavaScript](./src/find-the-duplicate-number/res.js)|Medium|
86+
|289|[Game of Life](https://leetcode.com/problems/game-of-life/)|[JavaScript](./src/game-of-life/res.js)|Medium|
8687
|299|[Bulls and Cows](https://leetcode.com/problems/bulls-and-cows/)|[JavaScript](./src/bulls-and-cows/res.js)|Medium|
8788
|307|[Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable/)|[JavaScript](./src/range-sum-query-mutable/res.js)|Medium|
8889
|309|[Best Time to Buy and Sell Stock with Cooldown](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/)|[JavaScript](./src/best-time-to-buy-and-sell-stock-with-cooldown/res.js)|Medium|

‎src/game-of-life/res.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
*@param {number[][]} board
3+
*@return {void} Do not return anything, modify board in-place instead.
4+
*/
5+
vargameOfLife=function(board){
6+
constn=board.length;
7+
constm=board[0].length;
8+
constflag=board.map(col=>col.map(()=>0));
9+
10+
// Flag
11+
for(leti=0;i<n;i++){
12+
for(letj=0;j<m;j++){
13+
constele=board[i][j];
14+
if(ele){
15+
for(lettbIndex=Math.max(i-1,0);tbIndex<Math.min(i+2,n);tbIndex++){
16+
for(letlrIndex=Math.max(j-1,0);lrIndex<Math.min(j+2,m);lrIndex++){
17+
if(tbIndex===i&&lrIndex===j)continue;
18+
flag[tbIndex][lrIndex]++;
19+
}
20+
}
21+
// console.log('new flag', flag)
22+
}
23+
}
24+
}
25+
26+
// console.log(flag);
27+
for(leti=0;i<n;i++){
28+
for(letj=0;j<m;j++){
29+
if(board[i][j]&&(flag[i][j]<2||flag[i][j]>3)){
30+
board[i][j]=0;
31+
}elseif(board[i][j]&&flag[i][j]>=2&&flag[i][j]<=3||!board[i][j]&&flag[i][j]===3){
32+
board[i][j]=1;
33+
}
34+
}
35+
}
36+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp