Number of Ways to Paint N × 3 Grid LeetCode solution in C++

1
class Solution {
2
public:
3
int numOfWays(int n) {
4
int mod = 1e9 + 7;
5
long long c2 = 6, c3 = 6;
6
for (int i = 2; i <= n; i++) {
7
long long temp = c3;
8
c3 = (2 * c3 + 2 * c2) % mod;
9
c2 = (2 * temp + 3 * c2) % mod;
10
}
11
return (c2 + c3) % mod;
12
}
13
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0