int n = s.size();
if(n == 0  s[0] == '0') return 0;
if(n == 1) return 1;
int res = 0,fn_1 = 1,fn_2 = 1;
for(int i = 1;i < n;i++){
int temp = fn_1;
if(isValid(s[i])&&isValid(s[i1],s[i])) res+=fn_1+fn_2;
if(!isValid(s[i])&&isValid(s[i1],s[i])) res+=fn_2;
if(isValid(s[i])&&!isValid(s[i1],s[i])) res+=fn_1;
if(!isValid(s[i])&&!isValid(s[i1],s[i])) return 0;
fn_1 = res;
fn_2 = temp;
res = 0;
}
return fn_1;
}
bool isValid(char a,char b){
return a == '1'(a == '2' && b <='6');
}
bool isValid(char a){
return a != '0';
}
My c++ 0ms DP solution O(n)


Great code! I slightly changed it as follows:
int numDecodings(string s) { int n = s.size(); if ( n == 0  s[0] == '0' ) return 0; if ( n == 1 ) return 1; int m1 = 1, m2 = 1, num; for ( int i = 1; i < n; i++ ) { num = 0; if ( !isValid(s[i]) && !isValid(s[i1], s[i]) ) return 0; if ( isValid(s[i]) ) num = m1; if ( isValid(s[i1], s[i]) ) num += m2; m2 = m1; m1 = num; } return num; }