diff --git a/README.md b/README.md index de9056c0..2216b90d 100644 --- a/README.md +++ b/README.md @@ -706,4 +706,5 @@ LeetCode |1406|[Stone Game III](https://leetcode.com/problems/stone-game-iii/)|c|[c++](./src/1406-Stone-Game-III/1406.cpp)|[python](./src/1406-Stone-Game-III/1406.py)|[go](./src/1406-Stone-Game-III/1406.go)|[js](./src/1406-Stone-Game-III/1406.js)|[java](./src/1406-Stone-Game-III/1406.java)|Hard| |1408|[String Matching in an Array](String Matching in an Array)|c|[c++](./src/1408-String-Matching-in-an-Array/1408.cpp)|[python](./src/1408-String-Matching-in-an-Array/1408.py)|[go](./src/1408-String-Matching-in-an-Array/1408.go)|[js](./src/1408-String-Matching-in-an-Array/1408.js)|[java](./src/1408-String-Matching-in-an-Array/1408.java)|Easy| |1409|[Queries on a Permutation With Key](https://leetcode.com/problems/queries-on-a-permutation-with-key/)|c|[c++](./src/1409-Queries-on-a-Permutation-With-Key/1409.cpp)|[python](./src/1409-Queries-on-a-Permutation-With-Key/1409.py)|[go](./src/1409-Queries-on-a-Permutation-With-Key/1409.go)|[js](./src/1409-Queries-on-a-Permutation-With-Key/1409.js)|[java](./src/1409-Queries-on-a-Permutation-With-Key/1409.java)|Medium| -|1410|[HTML Entity Parser](https://leetcode.com/problems/html-entity-parser/)|c|[c++](./src/1410-HTML-Entity-Parser/1410.cpp)|[python](./src/1410-HTML-Entity-Parser/1410.py)|[go](./src/1410-HTML-Entity-Parser/1410.go)|[js](./src/1410-HTML-Entity-Parser/1410.js)|[java](./src/1410-HTML-Entity-Parser/1410.java)|Medium| \ No newline at end of file +|1410|[HTML Entity Parser](https://leetcode.com/problems/html-entity-parser/)|c|[c++](./src/1410-HTML-Entity-Parser/1410.cpp)|[python](./src/1410-HTML-Entity-Parser/1410.py)|[go](./src/1410-HTML-Entity-Parser/1410.go)|[js](./src/1410-HTML-Entity-Parser/1410.js)|[java](./src/1410-HTML-Entity-Parser/1410.java)|Medium| +|1411|[Number of Ways to Paint N3 Grid](https://leetcode.com/problems/number-of-ways-to-paint-n-3-grid/)|c|[c++](./src/1411-Number-of-Ways-to-Paint-N3-Grid/1411.cpp)|[python](./src/1411-Number-of-Ways-to-Paint-N3-Grid/1411.py)|[go](./src/1411-Number-of-Ways-to-Paint-N3-Grid/1411.go)|[js](./src/1411-Number-of-Ways-to-Paint-N3-Grid/1411.js)|[java](./src/1411-Number-of-Ways-to-Paint-N3-Grid/1411.java)|Hard| \ No newline at end of file diff --git "a/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.cpp" "b/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.cpp" new file mode 100644 index 00000000..c4280cbf --- /dev/null +++ "b/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.cpp" @@ -0,0 +1,13 @@ +class Solution { +public: + int numOfWays(int n) { + long long aba = 6, abc = 6, t_aba, t_abc, mod = 1000000007; + for (int i = 0; i < n - 1; i++) { + t_aba = aba * 3 + abc * 2; + t_abc = aba * 2 + abc * 2; + aba = t_aba % mod; + abc = t_abc % mod; + } + return (aba + abc) % mod; + } +}; \ No newline at end of file diff --git "a/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.go" "b/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.go" new file mode 100644 index 00000000..cf765c98 --- /dev/null +++ "b/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.go" @@ -0,0 +1,8 @@ +func numOfWays(n int) int { + var aba, abc, mod int64 + aba, abc, mod = 6, 6, 1000000007 + for i := 0; i < n - 1; i++ { + aba, abc = (aba * 3 + abc * 2) % mod, (aba * 2 + abc * 2) % mod + } + return int((aba + abc) % mod) +} \ No newline at end of file diff --git "a/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.java" "b/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.java" new file mode 100644 index 00000000..30697a1f --- /dev/null +++ "b/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.java" @@ -0,0 +1,12 @@ +class Solution { + public int numOfWays(int n) { + long aba = 6, abc = 6, t_aba, t_abc, mod = 1000000007; + for (int i = 0; i < n - 1; i++) { + t_aba = aba * 3 + abc * 2; + t_abc = aba * 2 + abc * 2; + aba = t_aba % mod; + abc = t_abc % mod; + } + return (int)((aba + abc) % mod); + } +} \ No newline at end of file diff --git "a/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.js" "b/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.js" new file mode 100644 index 00000000..f7684db0 --- /dev/null +++ "b/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.js" @@ -0,0 +1,10 @@ +var numOfWays = function(n) { + let aba = 6, abc = 6, t_aba, t_abc, mod = 1000000007; + for (let i = 0; i < n - 1; i++) { + t_aba = aba * 3 + abc * 2; + t_abc = aba * 2 + abc * 2; + aba = t_aba % mod; + abc = t_abc % mod; + } + return (aba + abc) % mod; +}; \ No newline at end of file diff --git "a/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.py" "b/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.py" new file mode 100644 index 00000000..fe60fa37 --- /dev/null +++ "b/src/1411-Number-of-Ways-to-Paint-N\303\2273-Grid/1411.py" @@ -0,0 +1,6 @@ +class Solution: + def numOfWays(self, n: int) -> int: + aba, abc, mod = 6, 6, 10**9 + 7 + for i in range(n - 1): + aba, abc = aba * 3 + abc * 2, aba * 2 + abc * 2 + return (aba + abc) % mod \ No newline at end of file diff --git a/src/addProb.py b/src/addProb.py index 6fb55438..fd065ec5 100644 --- a/src/addProb.py +++ b/src/addProb.py @@ -2,10 +2,10 @@ import os, bisect # 题目名称 -name = "HTML Entity Parser" -ID = 1410 -url = "https://leetcode.com/problems/html-entity-parser/" -difficult = "Medium" +name = "Number of Ways to Paint N×3 Grid" +ID = 1411 +url = "https://leetcode.com/problems/number-of-ways-to-paint-n-3-grid/" +difficult = "Hard" prog = ['c', 'cpp', 'py', 'go', 'js', 'java']