Passed all cases on leetcode but giving runtime error


#1

int dp[1009][1009];

int recurse(const string& A,const string& B,int i,int j)
{
if(j==B.length())
return i==A.length();

if(i>A.length() || j>B.length())
 return false;

if(dp[i][j]!=-1)
 return dp[i][j];
 
if(j==B.length()-1 || B[j+1]!='*')
{
    if(i==A.length() || (A[i]!=B[j] && B[j]!='.'))
     return dp[i][j]=false;
    else
     return recurse(A,B,i+1,j+1);
}

else
{
    if(recurse(A,B,i,j+2))
     return dp[i][j]=true;
    
   int k=i;
    while(k<A.length() && (B[j]=='.' || A[k]==B[j]))
    {
        if(recurse(A,B,k+1,j+2))
         return dp[i][j]=true;
        
        k++;
    }
    
    
    return dp[i][j]=false;
    
}

}

int Solution::isMatch(const string A, const string B)
{
memset(dp,-1,sizeof(dp));
return recurse(A,B,0,0);
}


#2

use 2D vector rather than 2D array