-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cxx
More file actions
60 lines (42 loc) · 985 Bytes
/
Copy pathmain.cxx
File metadata and controls
60 lines (42 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
#include <gtest/gtest.h>
using namespace std;
class Solution {
public:
int numDecodings(string s) {
vector<int> dp(s.size()+2);
dp[s.size()] = 1;
dp[s.size()+1] = 0;
for (int i = s.size()-1;i>=0;i--){
int n = s[i] - '0';
if (n == 0 ){
if (i == 0 || (s[i-1] != '1' && s[i-1] != '2') ) return 0;
dp[i] = 0;
dp[i-1] = dp[i+1];
i--;
}else{
if (n >=3 || (n == 2 && i < s.size()-1 && s[i+1] - '0' > 6 ) ){
dp[i] = dp[i+1];
}else{
dp[i] = dp[i+1] + dp[i+2];
}
}
}
return dp[0];
}
};
struct T{
};
TEST(Solution,test){
T ts[] = {
{
},
};
Solution solution;
for (T t : ts){
}
}
int main() {
testing::InitGoogleTest();
return RUN_ALL_TESTS();
}