解题步骤:
参考代码:
class Solution {
public:bool isMatch(string s, string p) {int m=s.size();int n=p.size();//处理后续映射关系s=' '+s;//处理后续映射关系p=' '+p;vector<vector<bool>> dp(m+1,vector<bool>(n+1));//初始化dp[0][0]=true;for(size_t j=2;j<=n;j+=2){if(p[j]=='*'){dp[0][j]=true;}else{break;}}//填表for(size_t i=1;i<=m;i++){for(size_t j=1;j<=n;j++){if(p[j]=='*'){dp[i][j]=dp[i][j-2]||(p[j-1]=='.'||s[i]==p[j-1])&&dp[i-1][j];}else {dp[i][j]=(s[i]==p[j]||p[j]=='.')&&dp[i-1][j-1];}}}return dp[m][n];}
};