【leetcode】Regular Expression Matching
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的更多相关文章
- 【leetcode】Regular Expression Matching (hard) ★
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- leetcode 10 Regular Expression Matching(简单正则表达式匹配)
最近代码写的少了,而leetcode一直想做一个python,c/c++解题报告的专题,c/c++一直是我非常喜欢的,c语言编程练习的重要性体现在linux内核编程以及一些大公司算法上机的要求,pyt ...
- 【JAVA、C++】LeetCode 010 Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- 【leetcode刷题笔记】Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- LeetCode (10): Regular Expression Matching [HARD]
https://leetcode.com/problems/regular-expression-matching/ [描述] Implement regular expression matchin ...
- [leetcode]10. Regular Expression Matching正则表达式的匹配
Given an input string (s) and a pattern (p), implement regular expression matching with support for ...
- LeetCode之Regular Expression Matching
[题目描述] Implement regular expression matching with support for '.' and '*'. '.' Matches any single ch ...
- [LeetCode][Python]Regular Expression Matching
# -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/regular-expression-matching/ Implement reg ...
- 【LeetCode】44. Wildcard Matching (2 solutions)
Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...
随机推荐
- IIS站点无法访问..点浏览IIS窗口直接关掉
呃..其实这个问题很简单.. 大家可以先看这位大婶写的博文.. http://blog.csdn.net/chenguang79/article/details/7220232 如果网站一访问IIS就 ...
- Struts2 action的单例与多例
struts 2的Action是多实例的并非单例,也就是每次请求产生一个Action的对象.原因是:struts 2的Action中包含数据,例如你在页面填写的数据就会包含在Action的成员变量里面 ...
- [EWS]在exchange中的标识符
摘要 最近在用ews的方式开发邮箱服务,包括写邮件,查看某封邮件的详情,回复,全部回复及转发功能.在获取收件箱的时候,关于唯一标识符的问题.也有点困惑,在每个邮件item中,存在一个changeKey ...
- js中的全局变量和静态变量的使用, js 的调试?- 如果js出错, js引擎 就会停止, 这会 导致 后面的 html中 refer 该函数时, 会报错 函数为定义!!
效果里面的函数, 如show, hide,slideDown等, 这些都叫 "效果"函数, 但是里面可以包含动画, 也可以 不包含动画. 动画,是指 元素 的内容 是 逐渐 显示/ ...
- linux shell中判断bash脚本输入的参数个数
看下面的一段程序. #!/bin/bash ]; then echo "参数个数为$#个" else echo "没有参数" fi
- CF449C Jzzhu and Apples (筛素数 数论?
Codeforces Round #257 (Div. 1) C Codeforces Round #257 (Div. 1) E CF450E C. Jzzhu and Apples time li ...
- 正确使用Python logging
这篇文章主要参考: http://victorlin.me/posts/2012/08/26/good-logging-practice-in-python ===================== ...
- [设计模式] Javascript 之 观察者模式
观察者模式:定议 定义对象间的一种一对多的关系,当一个对象状态改变时 (一般称为被观察者),依赖于该对象的对象被通知,并更新; 观察者模式:说明 1. 观察者模式是行为模式,也被称为:发布-订阅模式. ...
- WPF中的数据绑定!!!
引用自:https://msdn.microsoft.com/zh-cn/magazine/cc163299.aspx 数据点: WPF 中的数据绑定 数据点 WPF 中的数据绑定 John Pap ...
- nyoj 14 会场安排问题(贪心专题)java
会场安排问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工 ...