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的更多相关文章

  1. 10.Regular Expression Matching (String; Back-Track,DP)

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

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

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

  3. [LeetCode] 10. Regular Expression Matching

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

  4. No.010:Regular Expression Matching

    问题: Implement regular expression matching with support for '.' and '*'.'.' Matches any single charac ...

  5. Regular Expression Matching

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

  6. 【leetcode】Regular Expression Matching

    Regular Expression Matching Implement regular expression matching with support for '.' and '*'. '.' ...

  7. 【leetcode】Regular Expression Matching (hard) ★

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

  8. 66. Regular Expression Matching

    Regular Expression Matching Implement regular expression matching with support for '.' and '*'. '.' ...

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

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

随机推荐

  1. C#中decimal的用法

    decimal拥有比float更高的精度,最高能处理到小数点后面的28位.适合用在财务类等对数字精确度要求比较高的场合. using System; using System.Collections. ...

  2. 转:说说JSON和JSONP,也许你会豁然开朗,含jQuery用例

    说到AJAX就会不可避免的面临两个问题,第一个是AJAX以何种格式来交换数据?第二个是跨域的需求如何解决?这两个问题目前都有不同的解决方案,比如数据可以用自定义字符串或者用XML来描述,跨域可以通过服 ...

  3. C#常用的内置委托

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  4. URL & webkitURL

    base64带来的坑 在web中想要是实现图片在线预览的方式有几种 1.先上传 2.使用FileReader对象 3.URL.createObjectURL(file|blob) base64 能将图 ...

  5. media type 与 media query

    参考博客:http://www.qianduan.net/media-type-and-media-query.html media type(媒体类型)是css 2中的一个非常有用的属性,通过med ...

  6. ORACLE触发器和new、old特殊变量

    :new --为一个引用最新的列值;:old --为一个引用以前的列值; 这两个变量只有在使用了关键字 "FOR EACH ROW"时才存在.且update语句两个都有,而inse ...

  7. php 对数组按某个字段进行排序

    //$arrays 需要排序的数组,$sort_key 需要排序的键名称 function my_sort($arrays,$sort_key,$sort_order=SORT_DESC,$sort_ ...

  8. Linux系统下用C语言获取MAC地址

    最近在做一个小程序,需要用到在linux系统里编写C程序从而获取MAC地址,从网上搜了一遍,想总结一下.如果你就只需要单个功能的程序,可以采用方法一,见代码1,一般最好能够封装起来,写成获取MAC地址 ...

  9. SpringMVC之数据绑定(转)

    到目前为止,请求已经能交给我们的处理器进行处理了,接下来的事情是要进行收集数据啦,接下来我们看看我们能从请求中收集到哪些数据, 1.@RequestParam绑定单个请求参数值: 2.@PathVar ...

  10. javascript事件设计模式

    JavaScript事件设计模式 http://plkong.iteye.com/blog/213543 http://www.docin.com/p-696665922.html