思路
要从2开始,前两个状态要有初始值
class Solution {
public:
int getTranslationCount(string s) {
int n =s.size();
vector<int> dp(n + 1);
dp[0] = 1;
dp[1] = 1;
for (size_t i = 2; i <=n; ++i) {
dp[i] = dp[i - 1];
auto num = (s[i-2]-'0')*10 + s[i-1]-'0';
if (num >= 10 && num <= 25)
dp[i] += dp[i - 2];
}
return dp[n];
}
};