迭代:
#include<iostream>
using namespace std;
class Solution
{
public: bool isMatch(const char *s, const char *p)
{
int i=0,j=0;
bool str=false;
for(;s[i]!='\0';i++,j++)
{
switch (p[j])
{
case '?':
break;
case '*':
while(p[j]=='*')
j++;
if(p[j]=='\0')
return true;
str=true;
i--;
j--;
break;
default:
if(s[i]!=p[j])
{
if(!str)
return false;
else
j--;
break;
}
}
}
while(p[j++]=='*');
return p[j]=='\0';
}
};
void main()
{
Solution solution;
cout<<solution.isMatch("aab","*a*b");
}