Advertisement
Ahmed_Negm

Untitled

Oct 1st, 2022
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     static int rec(string &s,int i=0){
  4.     if(i==s.size()) return 1;
  5.     if(s[i]=='0') return 0;
  6.     string s1="50";
  7.     if(i+2 <= s.size()) s1 = s.substr(i,2);
  8.     int ans1 =0;
  9.     int ans2= rec(s,i+1);
  10.     if(stoi(s1) >0 && stoi(s1) <=26){
  11.         ans1 = rec(s,i+2);
  12.     }
  13.     return ans1+ans2;
  14. }
  15.    
  16.     int numDecodings(string s) {
  17.     return rec(s);    
  18.     }
  19. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement