'?' 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. 20145105 《Java程序设计》实验五总结

    实验五 JAVA网络编程 一.实验内容 用老师给的代码,实现服务器和客户端 和结对同学实现服务器与客户端的连接 客户端输入数据并加密,将密文发送给服务器,服务器接收密文并解密 二.实验步骤 用老师给的 ...

  2. 《课程设计》——foremost的使用

    <课程设计>--foremost的使用 foremost简介 formost 是一个基于文件头和尾部信息以及文件的内建数据结构恢复文件的命令行工具.这个过程通常叫做数据挖掘(data ca ...

  3. 常用模块之hashlib,subprocess,logging,re,collections

    hashlib 什么是hashlib 什么叫hash:hash是一种算法(3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,M ...

  4. grep如何结尾匹配

    答:grep "jello$" 如:git branch输出以下内容: yes-jello-good yes-jellos yes-jello 那么使用以下命令只能过滤出一行: $ ...

  5. UDP的socketasynceventargs

    C# 使用 SocketAsyncEventArgs 实现UdpSocket系列 http://www.cnblogs.com/zwq194/archive/2012/10/30/2746393.ht ...

  6. Leetcode ——Lowest Common Ancestor of a Binary Tree

    Question Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. ...

  7. Cent OS 常用配置命令

    1.ifconfig   #查看网络接口状态 2.ifconfig –a  #查看主机所有接口的情况 3.ifconfig eth0 192.168.1.106 netmask 255.255.255 ...

  8. org.apache.axis2.AxisFault: java.lang.Error: Unresolved compilation problem:

    原创:转载请注明出处 今天遇到以下一个异常,找了好长时间,就是不知道什么原因, 在网上搜了好多,也没搜到相关的解决方法. 1.异常展示, org.apache.axis2.AxisFault: jav ...

  9. Ubuntu 14.04 删除软件附加依赖

    参考:FlowVisor的学习笔记 eg.mininet $ sudo apt-get remove mininet $ sudo apt-get remove --auto-remove minin ...

  10. 01_Kafka概述

    1.Kafka背景 * LinkedIn开发,2011年成为Apache的一个开源项目* 2012年,成为Apache的一个顶级项目* 基于java和Scala编写, 基于发布-订阅模型的消息系统(离 ...