Advertisement
otot957

Untitled

Feb 22nd, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. //Decode ways
  2. //runtime on case 223/258
  3. class Solution {
  4. public:
  5.     void backtrack(string s, int& count, int pos){
  6.         if(pos>= s.size()){
  7.             count++;
  8.             return;
  9.         }
  10.         if(s[pos]== '0')
  11.             return;
  12.         backtrack(s,count, pos+1);
  13.         //check if 2 digits is okay bs vslid l awl wla la2a
  14.         if(pos < s.size()-1 && (((s[pos]-'0')*10)+(s[pos+1]-'0'))  <= 26 )
  15.             backtrack(s,count, pos+2);
  16.        
  17.     }
  18.     int numDecodings(string s) {
  19.         int count=0;
  20.         backtrack(s,count, 0);
  21.         return count;
  22.     }
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement