public class Solution {
public int numDecodings(String s) {
int n = s.length();
if (n == 0) return 0;
int[] memo = new int[n+1];
memo[n] = 1;
memo[n1] = s.charAt(n1) != '0' ? 1 : 0;
for (int i = n  2; i >= 0; i)
if (s.charAt(i) == '0') continue;
else memo[i] = (Integer.parseInt(s.substring(i,i+2))<=26) ? memo[i+1]+memo[i+2] : memo[i+1];
return memo[0];
}
}
DP Solution (Java) for reference


Thanks for your post. However it would be better to share solution with elaborating thoughts. Please read the FAQ (http://oj.leetcode.com/discuss/faq) for more info. Take a look at good sharing example

I have the same idea, but the processing for memo[n1] is not necessary
if (s.empty()) return 0; vector<int> dp(s.size() + 1, 0); dp[s.size()] = 1; for (int i = s.size()  1; i >= 0; i) { if (s[i] == '0') { dp[i] = 0; continue; } dp[i] = dp[i + 1]; if (i < s.size()  1 && (s[i] == '1'  (s[i]=='2' && s[i + 1] < '7'))) { dp[i] += dp[i + 2]; } } return dp[0];