Skip to content

Commit

Permalink
add 1411
Browse files Browse the repository at this point in the history
  • Loading branch information
luliyucoordinate committed Apr 20, 2020
1 parent a163fad commit 883221e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
|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 N¡Á3 Grid](https://leetcode.com/problems/number-of-ways-to-paint-n-3-grid/)|c|[c++](./src/1411-Number-of-Ways-to-Paint-N¡Á3-Grid/1411.cpp)|[python](./src/1411-Number-of-Ways-to-Paint-N¡Á3-Grid/1411.py)|[go](./src/1411-Number-of-Ways-to-Paint-N¡Á3-Grid/1411.go)|[js](./src/1411-Number-of-Ways-to-Paint-N¡Á3-Grid/1411.js)|[java](./src/1411-Number-of-Ways-to-Paint-N¡Á3-Grid/1411.java)|Hard|
13 changes: 13 additions & 0 deletions src/1411-Number-of-Ways-to-Paint-N×3-Grid/1411.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
};
8 changes: 8 additions & 0 deletions src/1411-Number-of-Ways-to-Paint-N×3-Grid/1411.go
Original file line number Diff line number Diff line change
@@ -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)
}
12 changes: 12 additions & 0 deletions src/1411-Number-of-Ways-to-Paint-N×3-Grid/1411.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
10 changes: 10 additions & 0 deletions src/1411-Number-of-Ways-to-Paint-N×3-Grid/1411.js
Original file line number Diff line number Diff line change
@@ -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;
};
6 changes: 6 additions & 0 deletions src/1411-Number-of-Ways-to-Paint-N×3-Grid/1411.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions src/addProb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']


Expand Down

0 comments on commit 883221e

Please sign in to comment.