@@ -0,0 +1,1302 @@
+package com.fulin.DP;%0A%0A/**%0A * A message containing letters from A-Z is being encoded to numbers using the following mapping:%0A *   'A' -%3E 1%0A *   'B' -%3E 2%0A *   ...%0A *   'Z' -%3E 26%0A * Given an encoded message containing digits, determine the total number of ways to decode it.%0A * For example,%0A * Given encoded message %2212%22, it could be decoded as %22AB%22 (1 2) or %22L%22 (12).%0A * The number of ways decoding %2212%22 is 2.%0A *%0A *  Created by fulin on 17-8-10.%0A */%0Apublic class DecodeWays %7B%0A%0A    public int numDecodings(String s) %7B%0A        //%E5%A6%82%E6%9E%9C%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B8%BA%E7%A9%BA%EF%BC%8C%E5%88%99%E8%BF%94%E5%9B%9E0%0A        if(s == null %7C%7C s.length() == 0)%7B%0A            return 0;%0A        %7D%0A        // %E5%A6%82%E6%9E%9C%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%BB%A50%E5%BC%80%E5%A7%8B%EF%BC%8C%E5%88%99%E8%BF%94%E5%9B%9E0%0A        if(s.length() %3E 0 && s.charAt(0) == '0')%7B%0A            return 0;%0A        %7D%0A%0A        int m = s.length();%0A%0A        int%5B%5D ways = new int%5Bm + 1%5D;%0A%0A        //%E5%AF%B9%E6%95%B0%E7%BB%84%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0%E8%B5%8B%E5%80%BC%E4%B8%BA0 %E7%AC%AC%E4%BA%8C%E4%B8%AA%E5%85%83%E7%B4%A0%E8%B5%8B%E5%80%BC%E4%B8%BA1%0A        ways%5B0%5D = 1;%0A        ways%5B1%5D = 1;%0A%0A        for(int i=2;i%3C=m;i++)%7B%0A%0A            char current = s.charAt(i - 1);%0A            if('0' != current)%7B%0A                ways%5Bi%5D = ways%5Bi-1%5D;%0A            %7D%0A            // %E5%A6%82%E6%9E%9C %E5%BD%93%E5%89%8D%E5%85%83%E7%B4%A0%E4%B8%8E%E4%B9%8B%E5%89%8D%E7%9A%84%E5%85%83%E7%B4%A0%E7%BB%84%E6%88%90%E7%9A%84%E6%95%B0%E5%AD%97%E9%95%BF%E5%BA%A6%E6%98%AF10 - 26%E7%9A%84%E8%AF%9D%EF%BC%8C%E5%88%99%E6%96%B9%E5%BC%8F%E5%8F%AF%E4%BB%A5%E5%8A%A0%E4%B8%8A%E5%89%8D%E4%B8%A4%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E6%96%B9%E6%B3%95%0A            char pre = s.charAt(i-2);%0A            if((pre %3C '2' && pre %3E '0') %7C%7C(pre == '2' && current %3C= '6' ) )%7B%0A                ways%5Bi%5D += ways%5Bi - 2%5D;%0A            %7D%0A%0A%0A        %7D%0A%0A        return ways%5Bm%5D;%0A    %7D%0A%7D%0A

leetcode : 91. Decode Ways