# Leetcode Decode Ways 解题报告

A message containing letters from A-Z is being encoded to numbers using the following mapping:
'A' -> 1
'B' -> 2
...
'Z' -> 26
Given an encoded message containing digits, determine the total number of ways to decode it.

For example,
Given encoded message "12", it could be decoded as "AB" (1 2) or "L" (12).
The number of ways decoding "12" is 2.
http://oj.leetcode.com/problems/decode-ways/

1010，生成的number数组为：[1,1,1,1,1]
10000，生成的number数组为：[1,1,1,0,0,0,0,0,0]
AC代码：
public class Solution {
public int numDecodings(String s) {
if(s==null || s.length()==0) {
return 0;
}
if(s.charAt(0)=='0') {
return 0;
}

int [] number = new int[s.length() + 1];
number[0] = 1;
number[1] = 1;
int tmp;
for(int i=2;i<=s.length();i++) {
//检查当前字符是不是'0'
tmp = Integer.parseInt(s.substring(i-1,i));
if(tmp!=0) {
number[i] = number[i-1];
}
//检查当前字符和前一个字符组合在一起是否在1-26之间
if(s.charAt(i-2)!='0') {
tmp = Integer.parseInt(s.substring(i-2,i));
if(tmp>0&&tmp<=26) {
number[i] += number[i-2];
}
}
}
return number[s.length()];
}
}