Skip to content

Commit b64ad8b

Browse files
authored
Update 1411-number-of-ways-to-paint-n-3-grid.js
1 parent c49aa74 commit b64ad8b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

1411-number-of-ways-to-paint-n-3-grid.js

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
const numOfWays = function(n) {
6+
const mod = 1e9 + 7
7+
let colors3 = 6, colors2 = 6
8+
9+
for(let i = 1; i < n; i++) {
10+
const colors3Tmp = colors3
11+
colors3 = (2 * colors3 + 2 * colors2) % mod
12+
colors2 = (2 * colors3Tmp + 3 * colors2) % mod
13+
}
14+
15+
16+
return (colors2 + colors3) % mod
17+
};
18+
19+
// another
20+
21+
122
/**
223
* @param {number} n
324
* @return {number}

0 commit comments

Comments
 (0)