Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Decode ways
- //runtime on case 223/258
- class Solution {
- public:
- void backtrack(string s, int& count, int pos){
- if(pos>= s.size()){
- count++;
- return;
- }
- if(s[pos]== '0')
- return;
- backtrack(s,count, pos+1);
- //check if 2 digits is okay bs vslid l awl wla la2a
- if(pos < s.size()-1 && (((s[pos]-'0')*10)+(s[pos+1]-'0')) <= 26 )
- backtrack(s,count, pos+2);
- }
- int numDecodings(string s) {
- int count=0;
- backtrack(s,count, 0);
- return count;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement