Leetcode44. Wildcard Matching
题目:
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 lettersa-z
.p
could be empty and contains only lowercase lettersa-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相关推荐
- leetcode-44. Wildcard Matching
题目阐释: 正则匹配字符串,用程序实现 关键理解: 正则匹配,动态规划思想,一个个向后追溯,后面的依赖前面的匹配成功. 正则和待匹配的字符串长度不一,统一到正则字符串的index索引上,每次的字符串i ...
- LeetCode44 Wildcard Matching
题目: Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single charact ...
- [LeetCode] Wildcard Matching 题解
6. Wildcard Matching 题目 Implement wildcard pattern matching with support for '?' and '*'. '?' Matche ...
- [LintCode] Wildcard Matching
Wildcard Matching Implement wildcard pattern matching with support for '?'and '*'. '?' Matches any s ...
- [OJ] Wildcard Matching (Hard)
LintCode 192. Wildcard Matching (Hard) LeetCode 44. Wildcard Matching (Hard) 第二次刷还是被这题虐. 其实就是跪在一个地方, ...
- 【LeetCode】44. Wildcard Matching (2 solutions)
Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...
- leetcode44:wildcard
44. Wildcard Matching 问题描述 给定字符串s和模式p,判断字符串s是否完全符合模式p 其中字符串s只包含小写字母,模式串p包含小写字母.*.?,其中星号表示任意长度的任意字符串, ...
- LeetCode - 44. Wildcard Matching
44. Wildcard Matching Problem's Link --------------------------------------------------------------- ...
- 【To Understand! 重点 递归 动态规划 正则表达式匹配】LeetCode 44. Wildcard Matching
LeetCode 44. Wildcard Matching Solution1:我的答案 递归,时间复杂度是O(2n)O(2n)O(2^n)因为超时未能AC 只是记录一下,以警示后人-- class ...
- Wildcard Matching 1
Wildcard Matching 题解 题目描述 即判断字符串与正则表达式(只支持'?'和'*')是否匹配. '?'匹配任意一个字符,'*'匹配任意一个序列. 如:"abab"与 ...
最新文章
- iOS 注册密码加密 添加了时间戳 遇到的问题...
- Solr 建立多对多对象索引,检索时只显示了第一条
- 输入一字符串,统计其中有多少个单词(单词之间用空格分隔)(java)
- input全选和取消全选
- 阿拉伯数字转化为中文汉字(大、小写) - PHP
- python基础:变量与数据类型
- ifix组态软件研究控制按钮权限
- word-单独设置某一页的页眉或页脚
- access查找出生日期年份_Access时间日期比较查询的方法总结
- 熊国正版游戏之TXT文字乱码【已解决】【rutracker】【byrut】【单机】【破解】【俄罗斯】
- 计算机网络 期末复习
- 为什么你做数据分析没思路?
- 如何用 Roam Research 备课?
- 基于STM32cubemx的stm32f107vct6代码生成教程,实验一led闪烁
- 需求分析师如何提高核心竞争力
- Scrapy框架爬虫项目:京东商城笔记本电脑信息爬取
- JetBrains IDEA 2019.3 plugins|插件 搜索不到任何东西
- 安兰德《源泉》读后感:愿年轻人都能有志气
- Barrier (屏障; 障碍; 栅栏; 分界线)
- Tensorflow:BP神经网络权值初始化