Advertisement
akashtadwai

wildCardMatching

Aug 26th, 2021
1,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1.   bool isMatch(const string &s, const string &p) {
  2.          int n=s.size(),m=p.size();
  3.         dp[n][m]=true;
  4.         for(int i=m-1;i>=0;i--){
  5.             if(p[i]=='*') dp[n][i] = dp[n][i+1];
  6.         }
  7.         for(int i=n-1;i>=0;i--){
  8.             for(int j=m-1;j>=0;j--){
  9.                 if((p[j]=='?' or ( p[j]==s[i]))) dp[i][j] = dp[i+1][j+1];
  10.                 if(p[j]=='*') dp[i][j] = dp[i+1][j] || dp[i][j+1];
  11.             }
  12.         }
  13.         return dp[0][0];
  14.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement