fork download
  1. class Solution {
  2. public:
  3. int helper(string s,int n,vector<int> &dp){
  4. if(s[0] == '0'){
  5. return dp[n] = 0;
  6. }
  7.  
  8. if(n == 0 || n == 1){
  9. dp[n] = 1;
  10. }
  11. if(dp[n]!= -1){
  12. return dp[n];
  13. }
  14. dp[n]=0;
  15. if(s[n-1] > '0'){
  16. dp[n] = helper(s,n-1,dp);
  17. }
  18.  
  19. if((s[n-2] == '1') || (s[n-2] == '2' && s[n-1] < '7')){
  20. dp[n]+= helper(s,n-2,dp);
  21. }
  22.  
  23. return dp[n];
  24.  
  25. }
  26.  
  27. int numDecodings(string s) {
  28. int n = s.size();
  29. vector<int> dp(n+1,-1);
  30. int ans = helper(s,n,dp);
  31. for(int i=0;i<n+1;i++){
  32. cout << dp[i] << " ";
  33. }
  34. return ans;
  35.  
  36.  
  37. }
  38. };
  39.  
  40.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:12: error: ‘string’ has not been declared
 int helper(string s,int n,vector<int> &dp){
            ^~~~~~
prog.cpp:3:27: error: ‘vector’ has not been declared
 int helper(string s,int n,vector<int> &dp){
                           ^~~~~~
prog.cpp:3:33: error: expected ‘,’ or ‘...’ before ‘<’ token
 int helper(string s,int n,vector<int> &dp){
                                 ^
prog.cpp:27:18: error: ‘string’ has not been declared
 int numDecodings(string s) {
                  ^~~~~~
prog.cpp: In member function ‘int Solution::helper(int, int, int)’:
prog.cpp:4:7: error: invalid types ‘int[int]’ for array subscript
 if(s[0] == '0'){
       ^
prog.cpp:5:8: error: ‘dp’ was not declared in this scope
 return dp[n] = 0;
        ^~
prog.cpp:9:9: error: ‘dp’ was not declared in this scope
         dp[n] = 1;
         ^~
prog.cpp:11:8: error: ‘dp’ was not declared in this scope
     if(dp[n]!= -1){
        ^~
prog.cpp:14:5: error: ‘dp’ was not declared in this scope
     dp[n]=0;
     ^~
prog.cpp:15:13: error: invalid types ‘int[int]’ for array subscript
     if(s[n-1] > '0'){
             ^
prog.cpp:19:14: error: invalid types ‘int[int]’ for array subscript
     if((s[n-2] == '1') || (s[n-2] == '2' && s[n-1] < '7')){
              ^
prog.cpp:19:33: error: invalid types ‘int[int]’ for array subscript
     if((s[n-2] == '1') || (s[n-2] == '2' && s[n-1] < '7')){
                                 ^
prog.cpp:19:50: error: invalid types ‘int[int]’ for array subscript
     if((s[n-2] == '1') || (s[n-2] == '2' && s[n-1] < '7')){
                                                  ^
prog.cpp: In member function ‘int Solution::numDecodings(int)’:
prog.cpp:28:15: error: request for member ‘size’ in ‘s’, which is of non-class type ‘int’
     int n = s.size();
               ^~~~
prog.cpp:29:5: error: ‘vector’ was not declared in this scope
     vector<int> dp(n+1,-1);
     ^~~~~~
prog.cpp:29:12: error: expected primary-expression before ‘int’
     vector<int> dp(n+1,-1);
            ^~~
prog.cpp:30:26: error: ‘dp’ was not declared in this scope
     int ans = helper(s,n,dp);
                          ^~
prog.cpp:32:9: error: ‘cout’ was not declared in this scope
         cout << dp[i] << " ";
         ^~~~
stdout
Standard output is empty