package leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * https://leetcode.com/problems/decode-ways/
 */
public class Problem91 {
    public int numDecodings(String s) {
        Map<String, Character> charMap = getCharMap();
        return numDecodings(s, charMap, s.length()) + 1;
    }

    private int numDecodings(String s, Map<String, Character> map, int limit) {
        if (limit <= 2) {
            if (map.containsKey(s)) {
                return 1;
            }
            return 0;
        }
        int n = 0;
        for (int i = 0; i < s.length()-1; i++) {
            String s1 = s.substring(0, i+1);
            String s2 = s.substring(i+1);
            if (map.containsKey(s1)) {
                n++;
            }
            if (map.containsKey(s2)) {
                n++;
            }
            System.out.println(s1 + " " + s2);
            int n1 = numDecodings(s1, map, limit-1);
            int n2 = numDecodings(s2, map, limit-1);
            n += n1 + n2;
        }
        return n;
    }

    private Map<String, Character> getCharMap() {
        Map<String, Character> map = new HashMap<>();
        int c = (int) 'a';
        for (int i = 1; i <= 26; i++) {
            map.put(Integer.toString(i), (char) c);
            c++;
        }
        return map;
    }

    public static void main(String[] args) {
        Problem91 prob = new Problem91();
//        System.out.println(prob.numDecodings("12"));
//        System.out.println(prob.numDecodings("215"));
        System.out.println(prob.numDecodings("1215"));
    }
}

@@ -16,57 +16,8 @@
 e;%0A%0A
-import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A
@@ -143,259 +143,66 @@
     
-Map%3CString, Character%3E charMap = getCharMap();%0A        return numDecodings(s, charMap, s.length()) + 1;%0A    %7D%0A%0A    private int numDecodings(String s, Map%3CString, Character%3E map, int limit) %7B%0A        if (limit %3C= 2) %7B%0A            if (map.containsKey(s)
+return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args
 ) %7B%0A
@@ -213,950 +213,148 @@
     
-   
-     return 1;%0A            %7D%0A            return 0;%0A        %7D%0A        int n = 0;%0A        for (int i = 0; i %3C s.length()-1; i++) %7B%0A            String s1 = s.substring(0, i+1);%0A            String s2 = s.substring(i+1);%0A            if (map.containsKey(s1)) %7B%0A                n++;%0A            %7D%0A            if (map.containsKey(s2)) %7B%0A                n++;%0A            %7D%0A            System.out.println(s1 + %22 %22 + s2);%0A            int n1 = numDecodings(s1, map, limit-1);%0A            int n2 = numDecodings(s2, map, limit-1);%0A            n += n1 + n2;%0A        %7D%0A        return n;%0A    %7D%0A%0A    private Map%3CString, Character%3E getCharMap() %7B%0A        Map%3CString, Character%3E map = new HashMap%3C%3E();%0A        int c = (int) 'a';%0A        for (int i = 1; i %3C= 26; i++) %7B%0A            map.put(Integer.toString(i), (char) c);%0A            c++;%0A        %7D%0A        return map;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem91 prob = new Problem91(
+Problem91 prob = new Problem91();%0A//        System.out.println(prob.numDecodings(%2212%22));%0A        System.out.println(prob.numDecodings(%22215%22)
 );%0A/
@@ -396,26 +396,28 @@
 mDecodings(%22
-1
 2
+135
 %22));%0A//     
@@ -459,22 +459,25 @@
 ings(%2221
+2
 5%22));%0A
+//
         
@@ -514,16 +514,17 @@
 odings(%22
+2
 1215%22));

Update problem 91