标签:html htm ble while https etc 注意 www. strong
目录
Regular Expression Matching - LeetCode
解法一:参考Regular Expression Matching 正则表达式匹配。时间复杂度为O(n)
class Solution {
public:
bool firstCharIsMatch(char s,char p)
{
if(s == p || p == '.')
{
return true;
}
return false;
}
bool isMatch(string s, string p) {
if(p.empty() == true)
{
return s.empty();
}
if(p.length()==1)
{
return (s.length()==1 && firstCharIsMatch(s[0],p[0]));
}
if(p[1] != '*')
{
if(s.empty() == true)
{
return false;
}
return firstCharIsMatch(s[0],p[0])&&isMatch(s.substr(1),p.substr(1));
}
while(!s.empty()&&firstCharIsMatch(s[0],p[0]))
{
if(isMatch(s,p.substr(2)) == true)
{
return true;
}
s = s.substr(1);
}
return isMatch(s,p.substr(2));
}
};
Regular Expression Matching - LeetCode
标签:html htm ble while https etc 注意 www. strong
原文地址:https://www.cnblogs.com/multhree/p/10316396.html