'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence). 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", "*") → true
isMatch("aa", "a*") → true
isMatch("ab", "?*") → true
isMatch("aab", "c*a*b") → false 1. 动态规划
bool isMatch(string s, string p) {
int ls = s.length(), lp = p.length(), i, j;
vector<vector<bool>> dp(, vector<bool>(lp+, ));
bool k = ;
dp[][] = ;
for(i = ; i <= lp; i++)
dp[][i] = dp[][i-] && '*' == p[i-];
for(i = ; i <= ls; i++)
{
dp[k][] = ;
for(j = ; j <= lp; j++)
{
if('*' == p[j-])
dp[k][j] = dp[k][j-] || dp[!k][j];
else
dp[k][j] = dp[!k][j-] && (p[j-] == s[i-] || '?' == p[j-]);
}
k = !k;
}
return dp[!k][lp];
}

2. 不匹配的时候回到上一个星号的地方,使星号多匹配一个字符。

bool isMatch(string s, string p) {
int ls = s.length(), lp = p.length(), last_i = -, last_j = -, i = , j = ;
while(s[i])
{
if('*' == p[j])
{
j++;
if(!p[j])
return ;
last_i = i;
last_j = j;
}
else if(s[i] == p[j] || '?' == p[j])
{
i++;
j++;
}
else if(last_i != -)
{
i = ++last_i;
j = last_j;
}
else
return ;
}
while('*' == p[j])
j++;
return !p[j];
}

44. Wildcard Matching *HARD*的更多相关文章

  1. LeetCode - 44. Wildcard Matching

    44. Wildcard Matching Problem's Link --------------------------------------------------------------- ...

  2. 44. Wildcard Matching

    题目: Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single charact ...

  3. leetcode 10. Regular Expression Matching 、44. Wildcard Matching

    10. Regular Expression Matching https://www.cnblogs.com/grandyang/p/4461713.html class Solution { pu ...

  4. 【LeetCode】44. Wildcard Matching (2 solutions)

    Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...

  5. [LeetCode] 44. Wildcard Matching 外卡匹配

    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...

  6. 【一天一道LeetCode】#44. Wildcard Matching

    一天一道LeetCode系列 (一)题目 Implement wildcard pattern matching with support for '?' and '*'. '?' Matches a ...

  7. [leetcode]44. Wildcard Matching万能符匹配

    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...

  8. 44. Wildcard Matching (String; DP, Back-Track)

    Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...

  9. 44. Wildcard Matching 有简写的字符串匹配

    [抄题]: Given an input string (s) and a pattern (p), implement wildcard pattern matching with support ...

随机推荐

  1. 编译安装 http

    1. 安装 apr http服务依赖 apr和apr-util ,安装 http 前需先安装这两个程序 apr 简介:http://www.cnblogs.com/Alight/p/3997777.h ...

  2. mybatis 3的TypeHandler深入解析(及null值的处理)

    最近,在测试迁移公司的交易客户端连接到自主研发的中间件时,调用DAO层时,发现有些参数并没有传递,而在mapper里面是通过parameterMap传递的,因为有些参数为null,这就导致了参数传递到 ...

  3. C_Learning (1)

    /数据类型及占用字节 char   1个字节{-128~127} int    2.4个字节,取决于平台是16位还是32位机子{-65536~65535} short int  2个字节{-32768 ...

  4. noip 2013 提高组 Day2 部分题解

    积木大赛: 之前没有仔细地想,然后就直接暴力一点(骗点分),去扫每一高度,连到一起的个数,于是2组超时 先把暴力程序贴上来(可以当对拍机) #include<iostream> #incl ...

  5. C# MD5一句话加密

    System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5")

  6. linux指定某用户某组挂载外接硬盘以便操作硬盘

    一.环境:发行版本:ubuntu 14.04 64bit 二.获取要指定的用户及组id 使用id命令 (笔者获取的uid和gid都为1000) 三.获取识别的硬盘路径 sudo fdisk -l  ( ...

  7. Educational Codeforces Round 56 (Rated for Div. 2)

    涨rating啦.. 不过话说为什么有这么多数据结构题啊,难道是中国人出的? A - Dice Rolling 傻逼题,可以用一个三加一堆二或者用一堆二,那就直接.. #include<cstd ...

  8. .NET MVC请求流程

    ASP.NET MVC 请求流程:Controller MvcHandler Action Action参数赋值 .NET MVC权限设计思考之切入点

  9. 《重构网络:SDN架构与实现》Chapter7 SDN与网络虚拟化 随笔

    参考: <重构网络:SDN架构与实现>,作者:杨泽卫.李呈. Chapter7 SDN与网络虚拟化 结构 7.1 网络虚拟化 7.1.1 为什么需要网络虚拟化技术 7.1.2 网络虚拟化 ...

  10. python打包到pypi小结

       如果你写了一个python库,想让别人快速使用你的库,最简单的方式就是使用python官方出品的库托管网站pypi了.    pypi的全称是Python Package Index,是pyth ...