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

正则表达式的匹配,注意*代表的不是任意的字符,而是0个或者任意多个前向的字符,代码如下:

 class Solution {
public:
bool isMatch(string s, string p) {
if(p.size() == ) return s.size() == ;
if(p[] != '*'){
if(s.size() != && (p[] == s[] || p[] == '.'))
return isMatch(s.substr(), p.substr());
return false;
}else{
while(s.size() != &&(s[] == p[] || p[] == '.')){//模式串匹配0个或者更多的字符
if(isMatch(s, p.substr()))
return true;
s = s.substr();
}
return isMatch(s, p.substr());
}
}
};

LeetCode OJ:Regular Expression Matching(正则表达式匹配)的更多相关文章

  1. [LeetCode] 10. Regular Expression Matching 正则表达式匹配

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

  2. [LeetCode]10. Regular Expression Matching正则表达式匹配

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

  3. [LeetCode] Regular Expression Matching 正则表达式匹配

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

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

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

  5. 010 Regular Expression Matching 正则表达式匹配

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

  6. 10. Regular Expression Matching正则表达式匹配

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

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

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

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

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

  9. [LeetCode][Python]Regular Expression Matching

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

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

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

随机推荐

  1. Jmeter使用流程及简单分析监控(转载)

    转载自:https://www.cnblogs.com/linglingyuese/archive/2013/03/04/linglingyuese-one.html#undefined 一.安装Jm ...

  2. 使用Spring Session和Redis解决分布式Session跨域共享问题

    http://blog.csdn.net/xlgen157387/article/details/57406162 使用Spring Session和Redis解决分布式Session跨域共享问题

  3. 设置HTML5的video播放速度

    var speed = 1.5;//设置速度 var vdo = document.getElementById("视频的id");//获取id vdo.playbackRate ...

  4. Linux学习笔记之Xshell配色方案定制

    点击 Xshell 面板顶部的如下按钮. 点击 Browse 按钮,弹出如下面板,选择 ANSI Colors on Black,然后点击右侧save as 按钮,命名为 zkl.   这里其实就是复 ...

  5. Python3.x:BeautifulSoup()解决中文乱码问题

    Python3.x:BeautifulSoup()解决中文乱码问题 问题: BeautifulSoup获取网页内容,中文显示乱码: 解决方案: 遇到情况也是比较奇葩,利用chardet获取网页编码,然 ...

  6. bat(续七)-for语句(循环结构)

    for语句(循环结构) for语句可以实现类似于C语言里面的循环结构,当然for语句的功能要更强大一点,通过不同的开关可以实现更多的功能.for语句有多个开关,不同开关将会实现不同的功能.   1.无 ...

  7. C#设计模式之控制反转即依赖注入-Spring.NET

    主流的依赖注入方案:微软企业库中的Unity.Spring.NET.StructureMap.Ninject.Castle Windsor等等. 本章用简单的案例讲解 Spring.NET IOC-控 ...

  8. 如何将JS里变量的值赋给文本框

    举个栗子: <html><HEAD><script type="text/javascript" language="Javascript1 ...

  9. 使用 Python 连接 Caché 数据库

    有不少医院的 HIS 系统用的是 Caché 数据库,比如北京协和医院.四川大学华西医院等.用过 Caché 开发的都知道,Caché 数据库的开发维护同我们常见的关系型数据库有很大差别,如 SQL ...

  10. jQuery实际案例①——淘宝精品广告(鼠标触碰切换图片、自动轮播图片)

    遇到的问题:自动轮播的实现,实质与轮播图一样儿一样儿的,不要被不同的外表所欺骗,具体的js代码如下: