算法思路:动态规划
// C++ version
bool isMatch(string s, string p) {
string str;
for(auto it=p.begin();it<p.end();it++){//'*'去重
str.push_back(*it);
while((it+1)!=p.end()&&*it==*(it+1)&&*(it+1)=='*')it++;
}
p=str;
str.clear();
vector<vector<bool>> memo=vector<vector<bool>>(p.length()+1,vector<bool>(s.length()+1,false));
memo[0][0]=true;
for(int a=1;a<=p.length();a++)//状态转移
{
switch(int(p[a-1])){//开关速度更快
case int('*'):
for(int b=0;b<=s.length();b++){
if(memo[a-1][b])//如果找到可以匹配的点,即后面都可以匹配
while(b<=s.length())
memo[a][b++]=true;
else{
memo[a][b]=false;
}
}
break;
case int('?'):
for(int b=1;b<=s.length();b++){
if(memo[a-1][b-1])
memo[a][b]=true;
else{
memo[a][b]=false;
}
}
break;
default:
for(int b=1;b<=s.length();b++){
if(memo[a-1][b-1]&&p[a-1]==s[b-1])
memo[a][b]=true;
else{
memo[a][b]=false;
}
}
}
}
return memo[p.length()][s.length()];
}