第八周 Leetcode 44. Wildcard Matching 水题 (HARD)
实现一种类似正则表达式的字符串匹配功能。
复杂度要求不高, 调代码稍微费点劲。。
好像跟贪心也不太沾边, 总之 *把待匹配串分成若干个子串, 每一个子串尽量在模式串中靠前的部分匹配完成就算贪心了吧。。
class Solution {
public:
bool match(string &s,string &p,int l2,int r2,int l1)
{
if(l2==r2)return true;
if(l1+r2-l2-1>=s.length())return false;
while(l2<r2)
{
if(p[l2]=='?'){l1++;l2++;continue;}
if(s[l1]!=p[l2])return false;
l1++;l2++;
}
return true;
}
bool isMatch(string s, string p) {
s.append(1,'#');p.append(1,'#');
int l1=0,l2=0,r1=0,r2=0,len1=s.length(),len2=p.length();
while(true)
{
while(r2<len2&&p[r2]!='*')
r2++;
while(!match(s,p,l2,r2,l1))
{
if(l1>=len1)return false;
if(l2>0&&p[l2-1]=='*')l1++;
else return false;
}
l1+=r2-l2;
l2=r2+1;
r2=l2;
if(l1>=len1&&r2>=len2)return true;
if(r2>=len2)return false;
} }
};
第八周 Leetcode 44. Wildcard Matching 水题 (HARD)的更多相关文章
- LeetCode - 44. Wildcard Matching
44. Wildcard Matching Problem's Link --------------------------------------------------------------- ...
- [LeetCode] 44. Wildcard Matching 外卡匹配
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...
- [leetcode]44. Wildcard Matching万能符匹配
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...
- LeetCode 44 Wildcard Matching(字符串匹配问题)
题目链接:https://leetcode.com/problems/wildcard-matching/?tab=Description '?' Matches any single chara ...
- leetcode 44. Wildcard Matching(模糊匹配)
搬运工了- - https://blog.csdn.net/jmspan/article/details/51460021
- leetcode 10. Regular Expression Matching 、44. Wildcard Matching
10. Regular Expression Matching https://www.cnblogs.com/grandyang/p/4461713.html class Solution { pu ...
- 44. Wildcard Matching
题目: Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single charact ...
- 【LeetCode】44. Wildcard Matching (2 solutions)
Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...
- 【leetcode】Wildcard Matching
Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...
随机推荐
- layuiAdmin 项目修改
layuiAdmin修改 index.js 修改登录url user/login=>publics/login config.js 修改 name 项目名称, tokenName token字段 ...
- LINUX:Contos7.0 / 7.2 LAMP+R 下载安装Redis篇
文章来源:http://www.cnblogs.com/hello-tl/p/7569108.html 更新时间:2017-09-21 16:09 简介 LAMP+R指Linux+Apache+Mys ...
- PAT 1059. C语言竞赛
PAT 1059. C语言竞赛 C语言竞赛是浙江大学计算机学院主持的一个欢乐的竞赛.既然竞赛主旨是为了好玩,颁奖规则也就制定得很滑稽: 冠军将赢得一份"神秘大奖"(比如很巨大的一本 ...
- Codeforces Round #482 (Div. 2) C Kuro and Walking Route
C. Kuro and Walking Route time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- html5视频播放器 一 (改写默认样式)
一个项目用到了html5视频播放器,于是就写了一个,走了很多坑,例如在chrome中加载视频出现加载异常等 先看看效果 是不是感觉换不错,以下是我播放器改写样式的布局. <!DOCTYPE ht ...
- Property 'sqlMapClient' is required
继承SqlMapClientDaoSupport类的类里面添加如下代码 @Resource(name = "sqlMapClient") private SqlMapClient ...
- 纤程(FIBER)
Indy 10 还包含对纤程的支持.纤程是什么?简单来说,它也是 一个“线程”,但是它是由代码控制的,而不是由操作系统控制的.实际上,可以认为线程 是一个高级纤程.纤程和 Unix 用户线程(Unix ...
- linux 下 打包 和解压缩
01-.tar格式解包:[*******]$ tar xvf FileName.tar打包:[*******]$ tar cvf FileName.tar DirName(注:tar是打包,不是压缩! ...
- Kernel与用户进程通信
测试IPv6 ready logo rfc 3315的时候,遇到一个问题,要求在收到ICMPv6 RA的时候,DHCPv6 Client要发Solicit消息.在平常的应用中,都是启动DHCPv ...
- ubuntu语言设置成汉语
打开设置system setting,进入语言支持,有语言和地区格式.下载须要的语言并应用到整个系统. 按说明来就可以 这样的方法使得部分英语变为汉语.