'?' 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. 06: Django Admin

    目录:Django其他篇 01:Django基础篇 02:Django进阶篇 03:Django数据库操作--->Model 04: Form 验证用户数据 & 生成html 05:Mo ...

  2. zabbix配置自动发现,故障邮件告警

    对网段内的主机进行自动发现,自动加入主机组,自定加入template 创建动作时,类型这里选择discovery 然后将发现的主机加入host group和template: 动作针对的是discov ...

  3. Python3基础 list 推导式 生成与已知列表等长度+元素为0的列表

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  4. 括号序和dfs序

    记得清北讲过括号序和dfs序,忘记了 dfs序 dfs序就是dfs的顺序,这个好记 就是在dfs遍历树的时候,将每个结点开始时记录一次,结束时记录一次 而且一个子树可以表示为连续的一段, 只有子树操作 ...

  5. Trailing Zeroes (III) (二分)题解

    You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in d ...

  6. SpringJDBC源码分析记录

    我们使用JdbcTemplate时,调用的query方法为: public <T> List<T> query(String sql, @Nullable Object[] a ...

  7. dp入门 专题记录 2017-7-26

    POJ3176-Cow Bowling 题目大意:现有n行数,以金字塔的形式排列,即第一行一个数字,第二行2个数字,依次类推,现在需要找一条从第一层到第n层的路线,使得该路线上的所有点的权值和最大 思 ...

  8. Python非递归遍历多叉树

    class Queue: def __init__(self,max_size): self.max_size = int(max_size) self.queue = [] def put(self ...

  9. Java 文件夹递归遍历

    import java.io.File; public class Demo1 { public static void main(String[] args) { File dir=new File ...

  10. Z-score(Z值)的意义--转载

    http://blog.sina.com.cn/s/blog_72208a6a0101cdt1.html http://www.docin.com/p-350677620.html http://we ...