目录
题目
解法一
int numDecodings(char* s) {
const int mod = 1000000007;
const int len = strlen(s);
long cur, next = 1, nnext;
for (int i = len - 1; i >= 0; i--) {
if (s[i] == '0') {
cur = 0;
} else {
if (s[i] == '*') {
cur = 9 * next;
} else {
cur = next;
}
if (i + 1 < len) {
if (s[i] == '*') {
if (s[i + 1] == '*') {
cur += 15 * nnext;
} else if (s[i + 1] >= '0' && s[i + 1] <= '6') {
cur += 2 * nnext;
} else {
cur += nnext;
}
} else if (s[i + 1] == '*') {
if (s[i] == '1') {
cur += 9 * nnext;
} else if (s[i] == '2') {
cur += 6 * nnext;
}
} else if ((s[i] - '0') * 10 + (s[i + 1] - '0') <= 26) {
cur += nnext;
}
}
}
cur %= mod;
nnext = next;
next = cur;
}
return cur;
}