```
public int numDecodings(String s) {
if(s.length() == 0) return 0;
int pre = 26, digit, answer = 0, first = 1, second = 1;
for(int i = s.length() - 1; i >= 0; i--){
digit = s.charAt(i) - '0';
answer = digit == 0 ? 0 : first + (digit * 10 + pre <= 26 ? second : 0);
second = first;
first = answer;
pre = digit;
}
return answer;
}
```