Regular Expression Matching

Implement regular expression matching with support for '.' and '*'.

'.' Matches any single character.
'*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be:
bool isMatch(const char *s, const char *p) Some examples:
isMatch("aa","a") → false
isMatch("aa","aa") → true
isMatch("aaa","aa") → false
isMatch("aa", "a*") → true
isMatch("aa", ".*") → true
isMatch("ab", ".*") → true
isMatch("aab", "c*a*b") → true
 

 class Solution {
public:
bool isMatch(const char *s, const char *p) { if(s==NULL||p==NULL) return false;
if(*p=='\0'&&*s=='\0') return true;
if(*p=='\0'&&*s!='\0') return false; //如果模式串下一个字符为*
if(*(p+)=='*')
{
//循环比较当前字符与模式串字符是否相等
while((*s!='\0'&&*p=='.')||(*s==*p))
{
//防止这种情况出现:"aaa", "a*a"
if(isMatch(s,p+)) return true;
s++;
}
return isMatch(s,p+);
}
else if((*s!='\0'&&*p=='.')||*s==*p)
{
//如果当前元素相等,则开始匹配下一个元素
return isMatch(s+,p+);
}
return false;
}
};
 
 

【leetcode】Regular Expression Matching的更多相关文章

  1. 【leetcode】Regular Expression Matching (hard) ★

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

  2. leetcode 10 Regular Expression Matching(简单正则表达式匹配)

    最近代码写的少了,而leetcode一直想做一个python,c/c++解题报告的专题,c/c++一直是我非常喜欢的,c语言编程练习的重要性体现在linux内核编程以及一些大公司算法上机的要求,pyt ...

  3. 【JAVA、C++】LeetCode 010 Regular Expression Matching

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

  4. 【leetcode刷题笔记】Regular Expression Matching

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

  5. LeetCode (10): Regular Expression Matching [HARD]

    https://leetcode.com/problems/regular-expression-matching/ [描述] Implement regular expression matchin ...

  6. [leetcode]10. Regular Expression Matching正则表达式的匹配

    Given an input string (s) and a pattern (p), implement regular expression matching with support for  ...

  7. LeetCode之Regular Expression Matching

    [题目描述] Implement regular expression matching with support for '.' and '*'. '.' Matches any single ch ...

  8. [LeetCode][Python]Regular Expression Matching

    # -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/regular-expression-matching/ Implement reg ...

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

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

随机推荐

  1. yii2 funson86\yii2-setting

    Yii2 Setting for other application, especially for Yii2 Adminlte Installation The preferred way to i ...

  2. webapi支持跨域访问

    写在前面 在实际应用中,跨域请求还是比较常见的,如何上接口直接支持跨域的访问呢? demo 场景项目A有个接口用来获取用户列表,现在项目b也有个功能需要加载用户列表.这两个项目在两个域名下,至少端口好 ...

  3. iis7+ 禁止IP访问设置方法

    第一步:打开 管理工具-Internet 信息服务(IIS)管理器,打开网站,选中某个站点 第二步:双击IIS中的IP地址和域限制 第三步:在右栏操作,添加拒绝条目

  4. ubuntu用apt-get安装memcache

    转自:http://yangfutao2000.blog.163.com/blog/static/12162588201151635856858/ 先安装服务器端: apt-get install m ...

  5. PHP利用Curl实现多线程抓取网页和下载文件

    PHP 利用 Curl  可以完成各种传送文件操作,比如模拟浏览器发送GET,POST请求等等,然而因为php语言本身不支持多线程,所以开发爬虫程序效率并不高,一般采集 数据可以利用 PHPquery ...

  6. php缓存技术总结

          缓存是指临时文件交换区,电脑把最常用的文件从存储器里提出来临时放在缓存里,就像把工具和材料搬上工作台一样,这样会比用时现去仓库取更方便.因为缓存往往使用的是RAM(断电即掉的非永久储存), ...

  7. JQuery中的html(),text(),val()区别

    jQuery中.html()用为读取和修改元素的HTML标签,.text()用来读取或修改元素的纯文本内容,.val()用来读取或修改表单元素的value值. 1.HTML html():取得第一个匹 ...

  8. 增值税——基础知识

    一.增值税的概念 增值税是对从事销售货物或者提供加工.修理修配劳务以及从事进出口货物的单位和个人取得的增值额为课税对象征收的一种税. 增值额是指纳税人在生产.经营或劳务活动中所创造的新增价值,即纳税人 ...

  9. Spring配置bean文件的底层实现方式

    首先 bean文件如下: <beans> <bean id="date" class="java.util.Date"></bea ...

  10. STAR-H1208M集线器不支持同时挂载多个nfs

    今天在两个触摸屏上都加入了开机加载nfs的操作. 没想到会出现以下错误: pmap_getmaps.c: rpc problem: RPC: Unable to receive; errno = Co ...