标签:
class Solution {
public:
bool isMatchCore(string s, string p,int indexS,int indexP){
if (s[indexS] == ‘\0‘ && p[indexP] == ‘\0‘)
return true;
if (s[indexS] != ‘\0‘ && p[indexP] == ‘\0‘)
return false;
if (p[indexP + 1] == ‘*‘)
{
if (s[indexS] == p[indexP] || (p[indexP] == ‘.‘&&s[indexS] != ‘\0‘))
return isMatchCore(s, p, indexS, indexP + 2) || isMatchCore(s, p, indexS + 1, indexP + 2)
|| isMatchCore(s, p, indexS + 1, indexP);
else
{
isMatchCore(s, p, indexS, indexP + 2);
}
}
if (p[indexP] == ‘.‘&&s[indexS] != ‘\0‘)
return isMatchCore(s, p, indexS + 1, indexP + 1);
if (p[indexP]==s[indexS])
return isMatchCore(s, p, indexS + 1, indexP + 1);
return false;
}
bool isMatch(string s, string p) {
if (s == "" && p == "")
return false;
int indexS = 0,indexP = 0;
return isMatchCore(s, p, indexS, indexP);
}
};
显示超时了,暂时还没想到解决办法。
Regular Expression Matching [leetcode]
标签:
原文地址:http://www.cnblogs.com/chengxuyuanxiaowang/p/4518452.html