[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 ...
随机推荐
- Xcode5 配置 github
首先,要在github上,进行如下的操作: 1. github 官网 https://github.com 注册github账号. 2. 创建一个repository,命名为项目的名称,如 Gith ...
- MySql数据库学习--存储过程(1)
在MySQL 5中,终于引入了存储过程这一新特性,这将大大增强MYSQL的数据库处理能力.在本文中将指导读者快速掌握MySQL 5的存储过程的基本知识,带领用户入门. 存储过程介绍 存储过程是一组为了 ...
- win7使用右键导致死机、假死、explorer无法响应的解决方法
右键引起explorer无法响应,奔溃,主要是由于COMCTL32.DLL和COMCTL21.OCX文件引起的 描述:comctl32.dll是Windows应用程序公用GUI图形用户界面模块.报告提 ...
- jquery 实现简单拖拽
$.fn.drag = function(obj) { var dragging = false; var oDrag = $(obj); oDrag.mousedown(function(e) { ...
- Holding Bin-Laden Captive!(hdoj1085)代码并未完全看懂
We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But rec ...
- 测试框架mochajs详解
测试框架mochajs详解 章节目录 关于单元测试的想法 mocha单元测试框架简介 安装mocha 一个简单的例子 mocha支持的断言模块 同步代码测试 异步代码测试 promise代码测试 不建 ...
- 混合使用Azure LB和ILB访问相同web服务(2)
那么现在开始,我们配置下两台WEB服务器的Internal Load balancer: 打开Powershell,检查当前两台虚拟机的端点配置: Get-AzureVM -ServiceName ...
- createDocumentFragment
http://www.cnblogs.com/myjavascript/p/3708920.html 对于循环批量操作页面的DOM有很大帮助!利用文档碎片处理,然后一次性append,并且使用原生的j ...
- YY的困境:除了终止私有化 还有更多的担忧
界面 刘莎 已大热一段时间的中概股私有化浪潮随着中国股市的下跌而降温,很多在美上市的中概股不得不因此叫停私有化,欢聚时代(下称YY)首当其冲,成为私有化大军中首个被迫撤退的中资公司. 虽然从表面看,私 ...
- tomcat优化-有改protocol 和 缓存 集群方案
tomcat优化 在线上环境中我们是采用了tomcat作为Web服务器,它的处理性能直接关系到用户体验,在平时的工作和学习中,归纳出以下七种调优经验. 1. 服务器资源 服务器所能提供CPU.内存.硬 ...