Not sure why it is not working


#1

public class Solution {
public int numDecodings(String A) {
int [] dp=new int[A.length()+1];
dp[0]=1;
dp[1]=A.charAt(0)==‘0’? 0:1;
for (int j = 1; j < A.length(); j ++)
{ if (A.charAt(j) == ‘0’ && A.charAt(j - 1) != ‘1’ && A.charAt(j - 1) != ‘2’)
return 0;
}
for(int i=2;i<=A.length();i++)
{
int onedigit=Integer.valueOf(A.substring(i-1 ,i));
int twodigit=Integer.valueOf(A.substring(i-2 ,i));
if(onedigit >=1&&onedigit<=9)
{
dp[i]+=dp[i-1];
}
if(twodigit >=10 && twodigit <=26)
{
dp[i]+=dp[i-2];
}
}

    return dp[A.length()];
}

}


#2

you forgot to take modulo
use (a+b)%c = (a%c+b%c)%c