Sir,
Can you please tell me what is error in my code
Wildcard Pattern
Pls share your code by saving on ide so that I could check itβ¦
Pls follow the approach as:
bool wildcard(string text,string pattern){
int r = text.size();
int c = pattern.size();
bool dp[r+1][c+1]; //dp[i][j] denotes if the text till i and pattern till j match
for(int i=0;i<=r;i++){
dp[i][0] = dp[0][i] = false ;
}
dp[0][0] = true ; //Base case - Strings of 0 length always match
//If first character of pattern is * then mark (0,1) as true since * can be mapped with empty sequence as well
if(pattern[0] == '*'){
dp[0][1] = true ;
}
for(int i=0;pattern[i]=='*';i++){
dp[i][1] = true ;
}
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
if(text[i-1] == pattern[j-1]){
//If current character of each string matches then mark this as however its previous state was
dp[i][j] = dp[i-1][j-1];
}
else if(pattern[j-1] == '?'){
//Since ? can be mapped with all characters , do the same for this as well
dp[i][j] = dp[i-1][j-1];
}
else if(pattern[j-1] == '*'){
//Since * can be mapped with all strings , mark current state as OR of both previous states
dp[i][j] = dp[i-1][j] || dp[i][j-1] ;
}
else {
//Since no matching took place , mark this cell as false
dp[i][j] = false ;
}
}
}
return dp[r][c];
}
Sir i submitted solution but could not understand the error in my code so i downloaded the test cases.