File tree Expand file tree Collapse file tree 1 file changed +69
-0
lines changed Expand file tree Collapse file tree 1 file changed +69
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ #include < gtest/gtest.h>
3
+ using namespace std ;
4
+
5
+
6
+ // // START
7
+ /*
8
+ ## Decode Ways II
9
+
10
+ */
11
+
12
+ class Solution {
13
+ int M = 1000000007 ;
14
+ public:
15
+ int numDecodings (string s) {
16
+ vector<long > dp (s.length () + 1 );
17
+ dp[0 ] = 1 ;
18
+ dp[1 ] = s[0 ] == ' *' ? 9 : s[0 ] == ' 0' ? 0 : 1 ;
19
+ for (int i = 1 ; i < s.length (); i++) {
20
+ if (s[i] == ' *' ) {
21
+ dp[i + 1 ] = 9 * dp[i] % M;
22
+ if (s[i - 1 ] == ' 1' )
23
+ dp[i + 1 ] = (dp[i + 1 ] + 9 * dp[i - 1 ]) % M;
24
+ else if (s[i - 1 ] == ' 2' )
25
+ dp[i + 1 ] = (dp[i + 1 ] + 6 * dp[i - 1 ]) % M;
26
+ else if (s[i - 1 ] == ' *' )
27
+ dp[i + 1 ] = (dp[i + 1 ] + 15 * dp[i - 1 ]) % M;
28
+ } else {
29
+ dp[i + 1 ] = s[i] != ' 0' ? dp[i] : 0 ;
30
+ if (s[i - 1 ] == ' 1' )
31
+ dp[i + 1 ] = (dp[i + 1 ] + dp[i - 1 ]) % M;
32
+ else if (s[i - 1 ] == ' 2' && s[i] <= ' 6' )
33
+ dp[i + 1 ] = (dp[i + 1 ] + dp[i - 1 ]) % M;
34
+ else if (s[i - 1 ] == ' *' )
35
+ dp[i + 1 ] = (dp[i + 1 ] + (s[i] <= ' 6' ? 2 : 1 ) * dp[i - 1 ]) % M;
36
+ }
37
+ }
38
+ return (int ) dp[s.length ()];
39
+ }
40
+ };
41
+ // // END
42
+ struct T {
43
+
44
+ };
45
+
46
+ TEST (Solution, test) {
47
+ T ts[] = {
48
+ {
49
+
50
+ },
51
+ {
52
+
53
+ },
54
+
55
+ };
56
+
57
+ for (T t : ts) {
58
+ Solution solution;
59
+
60
+ }
61
+ }
62
+
63
+ int main () {
64
+ testing::InitGoogleTest ();
65
+
66
+ return RUN_ALL_TESTS ();
67
+ }
68
+
69
+
You can’t perform that action at this time.
0 commit comments