@@ -0,0 +1,1270 @@
+package dp;%0A%0A/**%0A * https://oj.leetcode.com/problems/decode-ways/%0A * A message containing letters from A-Z is being encoded to numbers using the following mapping:%0A * %3Cpre%3E%0A * 'A' -%3E 1%0A * 'B' -%3E 2%0A * ...%0A * 'Z' -%3E 26%0A * %3C/pre%3E%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 */%0Apublic class DecodeWays %7B%0A    public int numDecodings(String s) %7B%0A        int length = s == null ? 0 : s.length();%0A        if (length == 0 %7C%7C s.charAt(0) == '0') return 0;%0A        int%5B%5D ways = new int%5Blength%5D;%0A        ways%5B0%5D = 1;%0A        for (int i = 1; i %3C length; i++) %7B%0A            char cur = s.charAt(i);%0A            char pre = s.charAt(i - 1);%0A            if (cur %3C '0' %7C%7C cur %3E '9' %7C%7C (cur == '0' && (pre == '0' %7C%7C pre %3E '2'))) return 0;%0A            if (cur == '0') %7B%0A                ways%5Bi%5D = (i - 2 %3C 0 ? 1 : ways%5Bi - 2%5D);%0A            %7D else if (pre == '0' %7C%7C pre %3E '2' %7C%7C (pre == '2' && cur %3E '6')) %7B%0A                ways%5Bi%5D = ways%5Bi - 1%5D;%0A            %7D else %7B%0A                ways%5Bi%5D = ways%5Bi - 1%5D + (i - 2 %3C 0 ? 1 : ways%5Bi - 2%5D);%0A            %7D%0A        %7D%0A        return ways%5Blength - 1%5D;%0A    %7D%0A%7D%0A

decode ways