forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a163fad
commit 883221e
Showing
7 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters