044 Wildcard Matching 通配符匹配
实现一个支持 '?' 和 '*' 的通配符匹配。
'?' 匹配任何单个字符。
'*' 匹配任何数量的字符 (包括0个)。
匹配应覆盖 整个 输入字符串(而不是部分)。
这个函数原型为:
bool isMatch(const char *s, const char *p)
示例:
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
详见:https://leetcode.com/problems/wildcard-matching/description/
class Solution {
public:
bool isMatch(string s, string p) {
int m=s.size();
int n=p.size();
vector<vector<int>> dp(m+1,vector<int>(n+1));
dp[0][0]=true;
for(int i=1;i<=n;++i)
{
if(p[i-1]=='*')
{
dp[0][i]=dp[0][i-1];
}
}
for(int i=1;i<=m;++i)
{
for(int j=1;j<=n;++j)
{
if(p[j-1]=='*')
{
dp[i][j]=dp[i-1][j]||dp[i][j-1];
}
else
{
dp[i][j]=(s[i-1]==p[j-1]||p[j-1]=='?')&&dp[i-1][j-1];
}
}
}
return dp[m][n];
}
};
参考:https://www.cnblogs.com/grandyang/p/4401196.html
044 Wildcard Matching 通配符匹配的更多相关文章
- [Leetcode] Wildcard matching 通配符匹配
Implement wildcard pattern matching with support for'?'and'*'. '?' Matches any single character. '*' ...
- [LeetCode]Wildcard Matching 通配符匹配(贪心)
一開始採用递归写.TLE. class Solution { public: bool flag; int n,m; void dfs(int id0,const char *s,int id1,co ...
- [LeetCode] Wildcard Matching 外卡匹配
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...
- [LeetCode] 44. Wildcard Matching 外卡匹配
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...
- LeetCode 044 Wildcard Matching
题目要求:Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches ...
- Java for LeetCode 044 Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...
- [Swift]LeetCode44. 通配符匹配 | Wildcard Matching
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...
- [LeetCode][Facebook面试题] 通配符匹配和正则表达式匹配,题 Wildcard Matching
开篇 通常的匹配分为两类,一种是正则表达式匹配,pattern包含一些关键字,比如'*'的用法是紧跟在pattern的某个字符后,表示这个字符可以出现任意多次(包括0次). 另一种是通配符匹配,我们在 ...
- LeetCode 44. 通配符匹配(Wildcard Matching)
题目描述 给定一个字符串 (s) 和一个字符模式 (p) ,实现一个支持 '?' 和 '*' 的通配符匹配. '?' 可以匹配任何单个字符. '*' 可以匹配任意字符串(包括空字符串). 两个字符串完 ...
随机推荐
- MySQL多个条件以什么表当做主条件表_20161111周五
前两天有事情 停了2天 数据需求:1.活动日期11.8-11.10订单2.单笔订单购买A类产品 B类产品满足68元.且连续3天下单的用户ID 首先第一个条件很简单,主要是第二个条件 第二个条件是 且 ...
- BZOJ3165:[HEOI2013]Segment
浅谈标记永久化:https://www.cnblogs.com/AKMer/p/10137227.html 题目传送门:https://www.lydsy.com/JudgeOnline/proble ...
- HBase键值分片的简单运用
1.基本原理介绍 HBase的存储是通过行键建立索引进行存储的,而且HBase只支持一级索引,因此只要通过行键才能很快的找到需要的数据. HBase是一个分布式的系统,HBase通过行 ...
- 利用MEF实现插件机制(可根据输入类型来加载特定dll)
最近在做PACS的项目中想利用插件来加载各个不同的SCP的操作实现.比如Worklist的查询数据库,可以有多个实现. 比如MPPS的更新,也可以有多个实现. 为了统一弹性处理插件模块,增加了类型输入 ...
- vijos:P1155集合位置(次短路)
描述 每次有大的活动,大家都要在一起“聚一聚”,不管是去好乐迪,还是避风塘,或者汤姆熊,大家都要玩的痛快.还记得心语和花儿在跳舞机上的激情与释放,还记得草草的投篮技艺是如此的高超,还记得狗狗的枪法永远 ...
- 【转】值得推荐的C/C++框架和库
偶然间在博客园前辈那里看到的,转载备用,日后研究. 原文链接:http://www.cnblogs.com/findumars/p/6891515.html Webbench是一个在linux下使用的 ...
- linux 中C语言便于调试的宏定义编写及 __FILE__,__FUNCTION__, __LINE__参数使用
转自:http://blog.csdn.net/edonlii/article/details/8491342/ 在linux编程中,当文件数量变的众多之后,使用gdb调试就是一场灾难.因此在程序中加 ...
- Docker入门(五):Swarms
这个<Docker入门系列>文档,是根据Docker官网(https://docs.docker.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指 ...
- huipengly的2018年度总结
一.技术 1.入门C++ 今年看完了一本很厚很厚的书——<c++ primer 5th>.从头到尾,基本上每一个课后练习题都完成了.入门了C++这个大坑,也初步了解了面向对象这个程序抽象方 ...
- [hdu2586]How far away?(LCA)
题意:问树上两点之间的最短距离 解题关键:LCA模板题,在线做法,LCA->RMQ,用st表求解 这里是用first,rmq数组长度可以减半. #include<cstdio> #i ...