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. PHP:验证邮箱合法性

    文章来源:http://www.cnblogs.com/hello-tl/p/7592304.html /** * [verifyPhone description] 效验邮箱号合法性 * @para ...

  2. Python Pandas库的学习(一)

    今天我们来学习一下Pandas库,前面我们讲了Numpy库的学习 接下来我们学习一下比较重要的库Pandas库,这个库比Numpy库还重要 Pandas库是在Numpy库上进行了封装,相当于高级Num ...

  3. 爬虫基础spider 之(一) --- 初识爬虫

    爬虫概念 (spider,网络蜘蛛)通过互联网上一个个的网络节点,进行数据的提取.整合以及存储.从而获取我们想要的部分 robots协议 robots协议不是技术层面的协议,只是一个君子协定: 首先在 ...

  4. 新进Linux菜鸟,请多多关照

    早早知晓Linux的大名,一直未研究学习,近来看了kernel一些源代码,在网上搜过很多基础的知识.感觉这个Linux的世界很广大,值得好好深入学习.初生婴儿,呱呱落地,必先躺若干日后能坐,在学爬,进 ...

  5. C语言学习6

    int i; 定义整形变量i int *p;  p为指向整型数据的指针变量 int a[n]: 定义整形数组a,他有n个元素 int *p[n]:   定义指针数组p,它有n个指向整型数据的指针元素组 ...

  6. MQL5备忘(2016-8-28)

    MQL5备忘 快捷操作: ·Ctrl+Space------The List Names dropdown ·Ctrl+Shift+Space------Show Parameter Info 整数类 ...

  7. //……关于promise

    什么是promise? promise 翻译成中文的意思是 "承诺" ,一个承诺说出去了说明他是进行中的,承诺兑现了代表成功,没有兑现代表失败了. promise 对象的状态一旦发 ...

  8. C51 原创电子琴 (蜂鸣器/计时器/中断/矩阵按键)

    需求分析 用C51的16个矩阵按键当作两个八度的琴键 按下时发出相应音调的声音,静态数码管显示相应音符的数字. 为了解锁更多曲目,两个多的琴键设计成#4,显示时加上小数点 下图分别为1和#4的显示,其 ...

  9. SQLAlchemy(2):多表操作 & 连接方式及原生SQL

    一对多:ForeignKey multitb_models.py import datetime from sqlalchemy import create_engine # 引入 创建引擎 from ...

  10. 【IntelliJ】IDEA使用--字体、编码和基本设置

    IDEA这么高端的工具之前只是断断续续使用了一下,因为项目的开发都是在eclipse上,每次学习IDEA的使用都得上网搜索半天,今天自己整理一下,方便以后查阅. IDEA版本15.0.4 字体 界面字 ...