1 Star 0 Fork 0

xiangxiang/LeetCode-NOTES

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
solution.cpp 906 Bytes
一键复制 编辑 原始数据 按行查看 历史
默然 提交于 7年前 . update all algorithms.
class Solution
{
public:
bool match(string &s,string &p,int i,int j)
{
// pattern已匹配完,检查字符串是否匹配完
if(j == p.size())
return i == s.size();
// pattern中,当前待匹配字符的后一个字符为'*'的情况
if(p[j+1] == '*')
{
// 如果能匹配,则可以让'*'号重复0次或多重复1次;不能匹配,则让'*'号重复0次
if((s[i] == p[j] || p[j] == '.') && i<s.size())
return match(s,p,i,j+2) || match(s,p,i+1,j);
return match(s,p,i,j+2);
}
// pattern中,当前待匹配字符的后一个字符不为'*'的情况
if(s[i] == p[j] || p[j] == '.')
return match(s,p,i+1,j+1);
return false;
}
bool isMatch(string s, string p)
{
return match(s,p,0,0);
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xiangxiang920/LeetCode-NOTES.git
git@gitee.com:xiangxiang920/LeetCode-NOTES.git
xiangxiang920
LeetCode-NOTES
LeetCode-NOTES
master

搜索帮助