难度:2
A串和B串,B串中有特殊字符
'.' Matches any single character. '*' Matches zero or more of the preceding element.模拟之
设置两个索引PA,PB表示当前匹配到了该位置,从末尾到头匹配
class Solution
{
public:
bool isMatch(const char *s, const char *p)
{
if(*s == '\0' && *p == '\0')
{
return true;
}
while(*p != '\0')
{
if(*p == '.' && *s != '\0')
{
return isMatch(s+1,p+1);
}
else if(*p == '*')
{
while(*s != '\0')
{
if(isMatch(s,p+1)) return true;
s++;
}
bool flag=true;
while(*p!='\0')
{
p++;
if(*p != '*'&&*p!='\0')
{
flag=false;
break;
}
}
return flag;
}
else
{
if(*s == *p) return isMatch(s+1,p+1);
return false;
}
}
return false;
}
} ;