What is wrong in this?


#1
public class Solution {
    public boolean palindrome(String str) {
        int j=str.length()-1;
        for (int i=0;i<str.length()/2;i++) {
            if (str.charAt(i)!=str.charAt(j)) {
                return false;
            }
            j--;
        }
        return true;
    }
    public int minCut(String A) {
        Map<Integer,Integer> indMap = new HashMap();
        indMap.put(-1,-1);
        for (int i=0;i<A.length();i++) {
            for (int j=i;j<A.length();j++) {
                String sub = A.substring(i,j+1);
                if (palindrome(sub) && indMap.containsKey(i-1)) {
                    if (!indMap.containsKey(j)) {
                        indMap.put(j,1+indMap.get(i-1));
                    }
                    if (j==A.length()-1) {
                        return 1+indMap.get(i-1);
                    }
                }
            }
        }
        return A.length();
    }
}

#2

you missed this:
else{
int min = Math.min(indMap.get(j), 1+indMap.get(i-1));
indMap.put(j,min);
}