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) ,实现一个支持 '?' 和 '*' 的通配符匹配. '?' 可以匹配任何单个字符. '*' 可以匹配任意字符串(包括空字符串). 两个字符串完 ...
随机推荐
- ES 相似度算法设置(续)
Tuning BM25 One of the nice features of BM25 is that, unlike TF/IDF, it has two parameters that allo ...
- 使用js获取当前页面的url网址信息。
1.设置或获取整个 URL 为字符串: window.location.href 2.设置或获取与 URL 关联的端口号码: window.location.port 3.设置或获取 URL 的协议部 ...
- 注意!!一定要谨慎使用c/c++原生指针
使用指针,要非常小心,今天在做一个小游戏时,就碰到一个使用原生指针的问题,找了好几个小时,才定位到问题的所在,晕. 主要是顶层逻辑中引用了一个指针,而在业务逻辑中将此指针删除了.这种在代码量很少的情况 ...
- Katalon Recorder 自动录制 Selenium 爬虫脚本
相信很多小伙伴都用过 Selenium 来完成爬虫工作,今天就给大家带来一个神器,可以录制你的浏览器动作,然后直接生成 Selenium 脚本,是不是心动了? 1 Selenium 简介 Seleni ...
- 结合Django+celery二次开发定时周期任务
需求: 前端时间由于开发新上线一大批系统,上完之后没有配套的报表系统.监控,于是乎开发.测试.产品.运营.业务部.财务等等各个部门就跟那饥渴的饿狼一样需要 各种各样的系统数据满足他们.刚开始一天一个还 ...
- 基于STM32的uCGUI移植和优化
基于STM32的uCGUI移植和优化 首先在开始这个说明之前,要简要说明下具体的环境: 编译工具:MDK4.20 开发板:安富莱v2版开发板 调试器:JLink v8盗版 移植篇 相信大家有移植经验 ...
- Linux User
1.用户的工作目录,在/etc/passwd中查看 2.如果shell=bin/false(正常为bin/bash)代表禁止登录,这样就无法登录以及通过su进行切换: 3.修改,usermod -d ...
- TCP/IP详解卷1 - wireshark抓包分析
TCP/IP详解卷1 - 系列文 TCP/IP详解卷1 - 思维导图(1) TCP/IP详解卷1 - wireshark抓包分析 引言 在初学TCP/IP协议时,会觉得协议是一种很抽象的东西,通过wi ...
- 杂项-QRCode:ZXing
ylbtech-杂项-QRCode:ZXing 1.返回顶部 1. ZXing是一个开放源码的,用Java实现的多种格式的1D/2D条码图像处理库,它包含了联系到其他语言的端口.Zxing可以实现使用 ...
- jvm学习五: 方法执行过程
方法执行过程:Java各个大版本更新提供的新特性(需要简单了解)