diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/1411. Number of Ways to Paint N \303\227 3 Grid" "b/leetcode3/\354\240\225\354\247\204\354\230\201/1411. Number of Ways to Paint N \303\227 3 Grid" new file mode 100644 index 00000000..bef31d2c --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/1411. Number of Ways to Paint N \303\227 3 Grid" @@ -0,0 +1,20 @@ +/** + * @param {number} n + * @return {number} + */ +var numOfWays = function(n) { + const MOD = 1e9 + 7; + + let aba = 6; + let abc = 6; + + for (let i = 1; i < n; i++) { + const nextAba = (aba * 3 + abc * 2) % MOD; + const nextAbc = (aba * 2 + abc * 2) % MOD; + + aba = nextAba; + abc = nextAbc; + } + + return (aba + abc) % MOD; +};