What's wrong in my solution?


#1

int Solution::isMatch(const string A, const string B) {
int n=A.length();
int m=B.length();

vector<vector<bool>> dp(n+1,vector<bool>(m+2,false));
for(int i=0;i<=m+1;i++)
{
    if(i<=1)dp[0][i]=true;
    else if(B[i-2]=='*')dp[0][i]=dp[0][i-2];
    else dp[0][i]=false;
}
for(int i=1;i<=n;i++){
    dp[i][0]=false;
    dp[i][1]=false;
}
for(int i=1;i<=n;i++){
    for(int j=2;j<=m+1;j++)
    {
        if(B[j-2]=='*'){
            dp[i][j]=dp[i][j-2]||dp[i-1][j];
        }else if(B[j-2]=='.' || B[j-2]==A[i-1]){
            dp[i][j]=dp[i-1][j-1];
        }else{
            dp[i][j]=false;
        }
    }
}
display_dp(dp);
if(dp[n][m+1])return 1;
else return 0;

}

It is failing in the case

A : “baaaaaabaaaabaaaaababababbaab”
B : “…aaaa.abaabab*”

Expected output is 0 and my code is giving 1. Please help.