题目描述: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(*p == '\0') return *s == '\0'; //如果下一个字符不是*,那么就需要匹配当前的字符!
if(*(p + 1) != '*'){ //下一个字符相等,或者有一个是'.',则匹配成功
if(*p == *s || (*p == '.' && *s != '\0'))
return isMatch(s + 1, p + 1);
else
return false;
} //下一个字符是*,则当前字符可以为0个或多个!
else{
while(*p == *s || (*p == '.' && *s != '\0')){
if(isMatch(s, p + 2))
return true;
s++;
}
return isMatch(s, p + 2);
} }
};

LeetCode 010 Regular Expression Matching的更多相关文章

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

    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. 【LeetCode】010. Regular Expression Matching

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

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

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

  5. [LeetCode][Python]Regular Expression Matching

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

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

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

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

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

  8. Leetcode 10. Regular Expression Matching(递归,dp)

    10. Regular Expression Matching Hard Given an input string (s) and a pattern (p), implement regular ...

  9. [LeetCode] 10. Regular Expression Matching

    Implement regular expression matching with support for '.' and '*'. DP: public class Solution { publ ...

随机推荐

  1. 【Postman】使用Postman实现接口数据关联

    首先下载安装Postman直接打开官网,点击下载按钮即可完成下载https://www.getpostman.com/downloads/ 栗子业务场景:用户登录医生账户,查询自己的处方列表数据:用户 ...

  2. 前端未来趋势之原生API:Web Components

    声明:未经允许,不得转载. Web Components 现世很久了,所以你可能听说过,甚至学习过,非常了解了.但是没关系,可以再重温一下,温故知新. 浏览器原生能力越来越强. js 曾经的 JQue ...

  3. 2.5远程仓的库使用-2.7Git别名

    2.5 远程仓库的使用 查看远程仓库 git remote # -v 选项会显示需要读写远程仓库使用的 Git 保存的简写与其对应的 URL 添加远程仓库 git remote add <sho ...

  4. c#反转

    string[] arr = Console.ReadLine().Split(' '); string result = string.Empty; for (int i = arr.Count() ...

  5. 判断浏览器,还在用userAgent吗,你out了

    以下内容摘自http://www.cnblogs.com/rubylouvre/archive/2009/10/14/1583362.html //2010 4 16日更新 ie678 = !+&qu ...

  6. Linux 网络栈 转载

    此文章  来自      http://arthurchiao.art/blog/tuning-stack-rx-zh/ [译] Linux 网络栈监控和调优:接收数据(2016) Published ...

  7. JavaScript高级程序设计(第四版) -- 随笔 -- 数组(未完)

    数组方法 .every() 与 .some() 传给两个个方法的函数都接收3个参数:数组元素.元素索引和数组本身. .every() -- 对于每一项都需要返回true,它才会返回true 若中途有一 ...

  8. Java 微信端评论表情处理

    1,工具包下载:https://github.com/vdurmont/emoji-java 2,文本保存时处理:EmojiParser.parseToHtmlHexadecimal(str) 3,文 ...

  9. burp插件之跨站payload批量注入-xssValidator

    环境搭建 Phantomjs下载 csdn-burp使用xssValidator插件 cnblog-burp插件之xssValidator xssValidator使用 参考链接 cnblog-bur ...

  10. HW弹药库之红队作战手册

    红方人员实战手册 声明 Author : By klion Date : 2020.2.15 寄语 : 愿 2020 后面的每一天都能一切安好 分享初衷 一来, 旨在为 "攻击" ...