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. vim tab 中设置title

    在.bashrc添加 export PROMPT_COMMAND='echo -ne "\033]0;your wanted title\007"'

  2. QQ空间HD(2)-UIPopoverController其它使用

    DJTestViewController.m #import "DJTestViewController.h" #import "DJColorTableViewCont ...

  3. 配置red hat的ip 自动地址

    三个文件: 需要配置的内容包括: nameserver dns, hostname和gateway, ip地址等等. /etc/resolv.conf中配置dns, 这个也可以在 sysconfig/ ...

  4. highcharts图表中级入门之xAxis label:X(横)坐标刻度值过长截断多行(换行)显示问题说明

    在使用highcharts图表的过程中,总会碰到这样一个很是棘手的问题,横坐标刻度值太长,在不换行显示的情况下显得格外拥挤.虽然针对这一问题是可以对其刻度值进行旋转以此来避开显示拥挤问题[如何让hig ...

  5. ktouch移动端事件库

    最近闲来无事,写了个移动端的事件库,代码贴在下面,大家勿拍. /** @version 1.0.0 @author gangli @deprecated 移动端触摸事件库 */ (function ( ...

  6. nginx TCP 代理& windows傻瓜式安装

    一.下载nginx Windows http://nginx.org/en/download.html 二.解压到目录 三.进入目录并start nginx.exe即可启动 cd d:/java/ng ...

  7. 【AngularJS】—— 11 指令的交互

    前面基本了解了指令的相关内容: 1 如何自定义指令 2 指令的复用 本篇看一下指令之间如何交互.学习内容来自<慕课网 指令3> 背景介绍 这例子是视频中的例子,有一个动感超人,有三种能力, ...

  8. C语言:输入输出

    C语言无I/O语句,i/o操作由函数实现 #include<stdio.h> 字符输出函数putchar: 格式:putchar(c) 参数:c为字符常量,变量或者表达式 功能:把字符c输 ...

  9. PHP基础 之 基本数据类型练习

    <h3>PHP基础练习</h3> <?php echo "<h4>常量</h4>"; //定义:一般大写,使用下划线间隔 de ...

  10. CAN总线 SJA1000中断

    背景: 最近一直在使用C8051F340 + SJA1000来实现CAN通信,就SJA1000部分做个记录. 正文: 整个系统结构拓扑图如下: 两路CAN,C8051F340作为CPU,处理CAN与U ...