题目:

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

'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence).

The matching should cover the entire input string (not partial).
Note:

  • s could be empty and contains only lowercase letters a-z.
  • p could be empty and contains only lowercase letters a-z, and characters like ? or *.

代码(c++):

class Solution {public:bool isMatch(string s, string p) {//定义两个指针分别指向字符串s以及字符串pint pos_p = 0;//定义一个数组代表最优子问题的当前解vector<bool> dp_cur;dp_cur.push_back(true);for(int i = 0; i < s.length(); i++) dp_cur.push_back(false);//进行动态规划while(pos_p < p.length()) {vector<bool> dp_temp = dp_cur;//出现‘*’的情况if(p[pos_p] == '*') {//遍历for(int i = 0; i < dp_cur.size(); i++) {if(dp_cur[i] == true) {while(i < s.length()) {i++;dp_temp[i] = true;}}}pos_p = pos_p + 1;}//单字符情况else {//遍历for(int i = 0; i < dp_cur.size(); i++) {if(dp_cur[i] == true) {dp_temp[i] = false;while(i < s.length() && dp_cur[i] == true) {if(s[i] == p[pos_p] || p[pos_p] == '?') {i++;dp_temp[i] = true;}else break;}}}pos_p = pos_p + 1;}dp_cur = dp_temp;}if(dp_cur[s.length()] == true) return true;else return false;}
};

Leetcode44. Wildcard Matching相关推荐

  1. leetcode-44. Wildcard Matching

    题目阐释: 正则匹配字符串,用程序实现 关键理解: 正则匹配,动态规划思想,一个个向后追溯,后面的依赖前面的匹配成功. 正则和待匹配的字符串长度不一,统一到正则字符串的index索引上,每次的字符串i ...

  2. LeetCode44 Wildcard Matching

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

  3. [LeetCode] Wildcard Matching 题解

    6. Wildcard Matching 题目 Implement wildcard pattern matching with support for '?' and '*'. '?' Matche ...

  4. [LintCode] Wildcard Matching

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

  5. [OJ] Wildcard Matching (Hard)

    LintCode 192. Wildcard Matching (Hard) LeetCode 44. Wildcard Matching (Hard) 第二次刷还是被这题虐. 其实就是跪在一个地方, ...

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

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

  7. leetcode44:wildcard

    44. Wildcard Matching 问题描述 给定字符串s和模式p,判断字符串s是否完全符合模式p 其中字符串s只包含小写字母,模式串p包含小写字母.*.?,其中星号表示任意长度的任意字符串, ...

  8. LeetCode - 44. Wildcard Matching

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

  9. 【To Understand! 重点 递归 动态规划 正则表达式匹配】LeetCode 44. Wildcard Matching

    LeetCode 44. Wildcard Matching Solution1:我的答案 递归,时间复杂度是O(2n)O(2n)O(2^n)因为超时未能AC 只是记录一下,以警示后人-- class ...

  10. Wildcard Matching 1

    Wildcard Matching 题解 题目描述 即判断字符串与正则表达式(只支持'?'和'*')是否匹配. '?'匹配任意一个字符,'*'匹配任意一个序列. 如:"abab"与 ...

最新文章

  1. iOS 注册密码加密 添加了时间戳 遇到的问题...
  2. Solr 建立多对多对象索引,检索时只显示了第一条
  3. 输入一字符串,统计其中有多少个单词(单词之间用空格分隔)(java)
  4. input全选和取消全选
  5. 阿拉伯数字转化为中文汉字(大、小写) - PHP
  6. python基础:变量与数据类型
  7. ifix组态软件研究控制按钮权限
  8. word-单独设置某一页的页眉或页脚
  9. access查找出生日期年份_Access时间日期比较查询的方法总结
  10. 熊国正版游戏之TXT文字乱码【已解决】【rutracker】【byrut】【单机】【破解】【俄罗斯】
  11. 计算机网络 期末复习
  12. 为什么你做数据分析没思路?
  13. 如何用 Roam Research 备课?
  14. 基于STM32cubemx的stm32f107vct6代码生成教程,实验一led闪烁
  15. 需求分析师如何提高核心竞争力
  16. Scrapy框架爬虫项目:京东商城笔记本电脑信息爬取
  17. JetBrains IDEA 2019.3 plugins|插件 搜索不到任何东西
  18. 安兰德《源泉》读后感:愿年轻人都能有志气
  19. Barrier (屏障; 障碍; 栅栏; 分界线)
  20. Tensorflow:BP神经网络权值初始化

热门文章

  1. Visual Studio 2008 WPF设计器智能提示(Intellisense)失效
  2. 轻重搭配 模拟 贪心
  3. Keyboard项目中观察者模式解析
  4. 读《突然就走到了西藏》 | 保持呼吸,继续向前
  5. Win7从VHD中启动 如何扩充虚拟磁盘
  6. 【口语语言理解】新分类!全总结!最新Awesome-SLU-Survey资源库开源!
  7. 【Linux】修改权限命令chmod用法示例
  8. 最新语言表示方法XLNet
  9. 淦!这个非科班学妹是真的厉害...
  10. 统计学习方法读书笔记5-感知机代码实现