I am getting Segmentation fault in wildcard pattern matching in interviewBit and i seeked Help only to get no response by now. I am using DP to solve the task. Please help me figure out the reason of The segFault Link to the problem -- https://www.interviewbit.com/problems/regular-expression-match/
Here is my solution getting segFault in C++ .
int Solution::isMatch(const string &s, const string &p) {
int n=s.size(),m=p.size();
bool dp[n+1][m+1];
for(int i=0;i<=n;i++)for(int j=0;j<=m;j++)dp[i][j]=false;
dp[0][0]=true;
for(int j=1;j<=m;j++)
if(p[j-1]=='*')dp[0][j]=dp[0][j-1];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(s[i-1]==p[j-1] || p[j-1]=='?')dp[i][j]=dp[i-1][j-1];
else if(p[j-1]=='*')
{
int v1=dp[i][j-1],v2=0;// Not Using
v2=(dp[i-1][j]|dp[i][j-1]);
dp[i][j]=(v1|v2);
}
else dp[i][j]=false;
}
}
return dp[n][m];
}
Aucun commentaire:
Enregistrer un commentaire