[string]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(string& s,int sSize,int startS,string& p,int pSize,int startP)
{
if(startS==sSize){
while(startP<pSize){
if(p[startP]!='*' && (startP+>=pSize || p[startP+]!='*')){
break;
}
startP++;
}
return startP==pSize? true:false;
}
if(startP+<pSize && p[startP+]=='*'){
int j=startP+;
while(j<pSize && p[j]=='*') j++;
if(isMatch(s,sSize,startS,p,pSize,j)) return true;
while(startS<sSize && (s[startS]==p[startP] || p[startP]=='.')){
if(isMatch(s,sSize,++startS,p,pSize,j)) return true;
}
return false;
}
if(p[startP]=='.'||p[startP]==s[startS]){
return isMatch(s,sSize,startS+,p,pSize,startP+);
}
return false;
}
bool isMatch(string s, string p) {
return isMatch(s,s.size(),,p,p.size(),);
}
};
/*
"aaaaddcbbeefggh"
"a*ddcb*eefc*ggh**"
*/
通配符匹配:http://www.cnblogs.com/zengzy/p/5019079.html
[string]Regular Expression Matching的更多相关文章
- 10.Regular Expression Matching (String; Back-Track,DP)
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
Implement regular expression matching with support for '.' and '*'. DP: public class Solution { publ ...
- No.010:Regular Expression Matching
问题: Implement regular expression matching with support for '.' and '*'.'.' Matches any single charac ...
- Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- 【leetcode】Regular Expression Matching
Regular Expression Matching Implement regular expression matching with support for '.' and '*'. '.' ...
- 【leetcode】Regular Expression Matching (hard) ★
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- 66. Regular Expression Matching
Regular Expression Matching Implement regular expression matching with support for '.' and '*'. '.' ...
- 【JAVA、C++】LeetCode 010 Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
随机推荐
- Illustrated C#学习笔记(一)
迄今为止最容易看懂的一本C#入门图书,的确是,很不错的一本书,继续读下去,并做好相关笔记吧. Chapter 1 C#和.NET框架 主要讲述了一些.NET框架下的一些不明觉厉的名词如CLR,CLI. ...
- JAVA byte有无符号数的转换
如果你只需要对英文文本的每个字节进行数据处理,则无需考虑有符号数和无符号数的转换问题: 但如果你需要对含有中文的文本进行字节处理,则可能需要考虑有无符号数的转换问题. 以下代码均为Java代码. 1. ...
- Populating Next Right Pointers in Each Node,Populating Next Right Pointers in Each Node II
Populating Next Right Pointers in Each Node Total Accepted: 72323 Total Submissions: 199207 Difficul ...
- B - 敌兵布阵 线段树的点
B - 敌兵布阵 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descriptio ...
- JAVA多线程下,获取递增的序列号
场景描述: 1,目前我们的系统可以简单归纳成MVC的架构模式 2,每个前端的请求过来,都会在C层开启事务,最后处理结束后,也在在C层关闭事务(实际是在C层的底层统一做了事务的开启和提交): ...
- AngularJS如何给动态添加的DOM中绑定事件
正常情况(即非动态插入 DOM 对象)下,ng-click 这样的指令之所以有效(即点击之后能调用注册在可见作用域里的方法),是因为 angular 在 compiling phase(编译阶段)将宿 ...
- Nutch配置
http://www.linuxidc.com/Linux/2011-12/48782.htm http://wiki.apache.org/nutch/NutchHadoopTutorial htt ...
- wikioi1688 求逆序对
题目描述 Description 给定一个序列a1,a2,…,an,如果存在i<j并且ai>aj,那么我们称之为逆序对,求逆序对的数目 数据范围:N<=105.Ai<=105. ...
- OSCHina技术导向:web内容管理系统Magnolia
Magnolia简介: Magnolia CMS是一家瑞士公司自2003年起发布的一个基于Java的开源内容管理系统.它适合且已被使用在以下领域:电子商务(例如:COOP.Migros.Rossman ...
- 北京西服定做_衬衫定制_关于我们_Dimoon TLR.
北京西服定做_衬衫定制_关于我们_Dimoon TLR.