int n = s.size(); // a = f[i-2], b = f[i-1], c = f[i] int a = 0, b = 1, c = 0; for (int i = 1; i <= n; ++i) { c = (longlong)b * check1digit(s[i - 1]) % mod; if (i > 1) { c = (c + (longlong)a * check2digits(s[i - 2], s[i - 1])) % mod; } a = b; b = c; } return c; } };
publicintnumDecodings(String s) { intn= s.length(); // a = f[i-2], b = f[i-1], c = f[i] longa=0, b = 1, c = 0; for (inti=1; i <= n; ++i) { c = b * check1digit(s.charAt(i - 1)) % MOD; if (i > 1) { c = (c + a * check2digits(s.charAt(i - 2), s.charAt(i - 1))) % MOD; } a = b; b = c; } return (int) c; }
publicintNumDecodings(string s) { int n = s.Length; // a = f[i-2], b = f[i-1], c = f[i] long a = 0, b = 1, c = 0; for (int i = 1; i <= n; ++i) { c = b * Check1digit(s[i - 1]) % MOD; if (i > 1) { c = (c + a * Check2digits(s[i - 2], s[i - 1])) % MOD; } a = b; b = c; } return (int) c; }
n = len(s) # a = f[i-2], b = f[i-1], c = f[i] a, b, c = 0, 1, 0 for i inrange(1, n + 1): c = b * check1digit(s[i - 1]) if i > 1: c += a * check2digits(s[i - 2], s[i - 1]) c %= mod a = b b = c return c
var numDecodings = function(s) { constMOD = 1000000007; const n = s.length; // a = f[i-2], b = f[i-1], c = f[i] let a = 0, b = 1, c = 0; for (let i = 1; i <= n; ++i) { c = b * check1digit(s[i - 1]) % MOD; if (i > 1) { c = (c + a * check2digits(s[i - 2], s[i - 1])) % MOD; } a = b; b = c; } return c; }
funccheck1digit(ch byte)int { if ch == '*' { return9 } if ch == '0' { return0 } return1 }
funccheck2digits(c0, c1 byte)int { if c0 == '*' && c1 == '*' { return15 } if c0 == '*' { if c1 <= '6' { return2 } return1 } if c1 == '*' { if c0 == '1' { return9 } if c0 == '2' { return6 } return0 } if c0 != '0' && (c0-'0')*10+(c1-'0') <= 26 { return1 } return0 }
funcnumDecodings(s string)int { const mod int = 1e9 + 7 a, b, c := 0, 1, 0 for i := range s { c = b * check1digit(s[i]) % mod if i > 0 { c = (c + a*check2digits(s[i-1], s[i])) % mod } a, b = b, c } return c }