Leetcode#91 Decode Ways

原题地址

动态规划题,注意0导致的小陷阱。

代码:

 int numDecodings(string s) {
if (s.empty() || s[] < '' || s[] > '') return ; int sum = s[s.length() - ] >= '' && s[s.length() - ] <= '' ? : ;
int nextnext = ;
int next = sum; for (int i = s.length() - ; i >= ; i--) {
if (s[i] >= '' && s[i] <= '') {
if (s[i] == '' || (s[i] == '' && s[i + ] >= '' && s[i + ] <= ''))
sum = next + nextnext;
else if (s[i] == '')
sum = ;
else
sum = next;
nextnext = next;
next = sum;
}
else
return ;
} return sum;
}
上一篇:leveldb源码分析--SSTable之TableBuilder


下一篇:Excepion