Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int dp[110];
- int numDecodings(string s) {
- int len = s.size();
- if(s[0] == '0') return 0;
- dp[0] = dp[1] = 1;
- for(int i=2;i<=len;i++){
- if(s[i-1] != '0')
- dp[i] += dp[i-1];
- if(i > 1 and ((s[i-2] == '1') or (s[i-2] == '2' and s[i-1] <= '6')))
- dp[i] += dp[i-2];
- }
- return dp[len];
- }
- };
Add Comment
Please, Sign In to add comment