第八周 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 ...
随机推荐
- Android四大核心组件之Activity
一.活动生命周期 二.生命周期执行介绍 当该页面(Activity)被启动时 会执行onCreate().onStart().onRestart()这三个方法, 只有当onRestart() 方法执行 ...
- Inspector's Dilemma(欧拉通路)
In a country, there are a number of cities. Each pair of city is connected by a highway, bi-directio ...
- CC3200 TI 笔记
I2C I2C总线是由Philips公司开发的一种简单.双向二线制同步串行总线.它只需要两根线即可在连接于总线上的器件之间传送信息. I2S I2S(Inter-IC Sound)总线, 又称 集成电 ...
- 60. Spring Boot写后感【从零开始学Spring Boot】
从2016年4月15日到2016年7月20日经历长达3个月的时间,[从零开始学习Spring Boot]系列就要告一段落了.国内的各种资源都比较乱或者是copy 来copy去的,错了也不加以修正下,导 ...
- CentOS下LVS DR模式负载均衡配置详解
一安装LVS准备: 1.准备4台Centos 6.2 x86_64 注:本实验关闭 SELinux和IPtables防火墙. 管理IP地址 角色 备注 192.168.1.101 LVS主调度器(Ma ...
- MySQL中间件之ProxySQL_读写分离/查询重写配置
MySQL中间件之ProxySQL_读写分离/查询重写配置 Posted on 2016-12-25 by mark blue, mark Leave a comment MySQL 1.闲扯几句 读 ...
- Codeforces Round #261 (Div. 2) E (DP)
E. Pashmak and Graph Pashmak's homework is a problem about graphs. Although he always tries to do hi ...
- ModelForm组件和forms组件补充
forms组件补充: forms组件的三个字段:ChoiceField, ModelChoiceField & ModelMultipleChoiceField # forms组件:Choic ...
- 【51NOD1766】树上的最远点对(线段树,LCA,RMQ)
题意:n个点被n-1条边连接成了一颗树,给出a~b和c~d两个区间, 表示点的标号请你求出两个区间内各选一点之间的最大距离,即你需要求出max{dis(i,j) |a<=i<=b,c< ...
- 无权二分图最大匹配 HDU2063 匈牙利算法 || Hopcroft-Karp
参考两篇比较好的博客 http://www.renfei.org/blog/bipartite-matching.html http://blog.csdn.net/thundermrbird/art ...