Leetcode 44

实现一种类似正则表达式的字符串匹配功能。

复杂度要求不高, 调代码稍微费点劲。。

好像跟贪心也不太沾边, 总之 *把待匹配串分成若干个子串, 每一个子串尽量在模式串中靠前的部分匹配完成就算贪心了吧。。

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)的更多相关文章

  1. LeetCode - 44. Wildcard Matching

    44. Wildcard Matching Problem's Link --------------------------------------------------------------- ...

  2. [LeetCode] 44. Wildcard Matching 外卡匹配

    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...

  3. [leetcode]44. Wildcard Matching万能符匹配

    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...

  4. LeetCode 44 Wildcard Matching(字符串匹配问题)

    题目链接:https://leetcode.com/problems/wildcard-matching/?tab=Description   '?' Matches any single chara ...

  5. leetcode 44. Wildcard Matching(模糊匹配)

    搬运工了- - https://blog.csdn.net/jmspan/article/details/51460021

  6. leetcode 10. Regular Expression Matching 、44. Wildcard Matching

    10. Regular Expression Matching https://www.cnblogs.com/grandyang/p/4461713.html class Solution { pu ...

  7. 44. Wildcard Matching

    题目: Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single charact ...

  8. 【LeetCode】44. Wildcard Matching (2 solutions)

    Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...

  9. 【leetcode】Wildcard Matching

    Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...

随机推荐

  1. U盘启动盘制作工具(安装Linux)

    2018-09-15 17:36:42 1. Etcher  官网:https://etcher.io/ 资料来源:https://linuxmint-installation-guide.readt ...

  2. oracle 11g完全卸载

    oracle 11g release2的完全卸载方式与前些版本有了改变,自带了一个卸载批处理文件——deinstall.bat.(这个工具可以从oracle的home进行完全的卸载,不管是单实例ora ...

  3. 带FIFO的UART数据接收

    芯片手册 某个Cortex-M4芯片带有1个UART,支持Tx,Rx 的FIFO功能,而且可以通过寄存器配置FIFO的阈值,芯片的datasheet并不完善,没有说明RX的FIFO具体有几个级别,每隔 ...

  4. Vertex&Frag

    一.Vertex&Frag 包含Vertex&Fragment 的Shader叫做顶点&像素着色器,在Vertex的功能函数中,我们侧重于几何计算,如纹理坐标,顶点坐标等:在F ...

  5. python接口自动化测试(一)

    本节开始,开始介绍python的接口自动化测试,首先需要搭建python开发环境,到https://www.python.org/下载python 版本直接安装就以了,建议 下载python2.7.1 ...

  6. 常用生产环境的PHP安装参数

    ./configure --prefix=/usr/local/php5. --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/b ...

  7. [NOIP2006] 提高组 洛谷P1064 金明的预算方案

    题目描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过N元钱就行”.今 ...

  8. BZOJ2272: [Usaco2011 Feb]Cowlphabet 奶牛文字

    n<=250个大写字母和m<=250个小写字母,给p<=200个合法相邻字母,求用这些合法相邻字母的规则和n+m个字母能合成多少合法串,答案mod 97654321. 什么鬼膜数.. ...

  9. 从零开始写STL—栈和队列

    从零开始写STL-栈和队列 适配器模式 意图:将一个类的接口转换成客户希望的另外一个接口.适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 主要解决:主要解决在软件系统中,常常要将 ...

  10. 使用HttpClient调用第三方接口

    最近项目中需要调用第三方的Http接口,这里我用到了HttpClient. 首先我们要搞明白第三方接口中需要我们传递哪些参数.数据,搞明白参数以后我们就可以使用HttpClient调用接口了. 1.调 ...