1/**
2 * @param {string} s
3 * @return {number}
4 */
5var numDecodings = function(s) {
6 var len = s.length;
7 var tmp = 0;
8 var tmp1 = 1;
9 var tmp2 = 0;
10 var num1 = 0;
11 var num2 = 0;
12
13 if (s === '' || s[0] === '0') return 0;
14
15 for (var i = 1; i <= len; i++) {
16 num1 = Number(s.substr(i - 1, 1));
17 num2 = Number(s.substr(i - 2, 2));
18 if (num1 !== 0) tmp += tmp1;
19 if (10 <= num2 && num2 <= 26) tmp += tmp2;
20 tmp2 = tmp1;
21 tmp1 = tmp;
22 tmp = 0;
23 }
24
25 return tmp1;
26};
27