```
class Solution {
public:
int numDecodings(string s) {
//动态规划
if(s.size()==0 || s[0]=='0') return 0;
int last1 = 1,last2 = 1;
for(int i = 1;i<s.size() && last1!=0;i++)
{
int cur = 0;
if(s[i]!='0') cur+=last1;
if(s[i-1]=='1' || (s[i-1]=='2' && s[i]<='6')) cur+=last2;
last2 = last1;
last1 = cur;//如果中间遇到了0 则直接返回0
}
return last1;
}
};
```