LeetCode #44 - Wildcard Matching

Leetcode #44. Wildcard Matching 通配符匹配 解题报告 1 解题思想嗯,最近遇到要写Hard的频率偏高,而最近的重心也不再Leetcode上,心累。。Hard写起来都好麻烦。这道题好像之前也有几次,讲过类似的题目,也就是*能任意长度和字符匹配,?能匹配任意一个字符,现在需要验证给定的通配符是否能匹配输入的串这道题应该有很多做法,我的这个感觉只是一个比较一般的解法,这道题的测试量比较大,所以单纯的暴力搜索是AC不掉的,而我的做法,就是使用动态规划。不知道大 阅读详情

题目描述:

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 *.

Example 1:

Input:
s = "aa"
p = "a"
Output: false
Explanation: "a" does not match the entire string "aa".

Example 2:

Input:
s = "aa"
p = "*"
Output: true
Explanation: '*' matches any sequence.

Example 3:

Input:
s = "cb"
p = "?a"
Output: false
Explanation: '?' matches 'c', but the second letter is 'a', which does not match 'b'.

Example 4:

Input:
s = "adceb"
p = "*a*b"
Output: true
Explanation: The first '*' matches the empty sequence, while the second '*' matches the substring "dce".

Example 5:

Input:
s = "acdcb"
p = "a*c?b"
Output: false

外卡匹配, “?”匹配任意一个字符,“*”匹配任意一串字符,包括空字符串。

与正则表达式匹配类似,还是采用动态规划,x[i][j]表示s的前i个字符和p的前j个字符匹配。如果p[j]!=’*‘,那么s[i]必须与p[j]匹配,即(s[i]==p[j]||p[j]=='?')&&x[i-1][j-1]==true;如果p[j]=='*',那么p[j]可以匹配空字符串,即x[i][j-1]==true即可,或者匹配任意长度的字符串,也就是从x[0][j]到x[i-1][j]存在一个为真,那么x[i][j]为真,实际操作判断更为简单,只需要当x[k-1][j]==true,令x[k][j]=true即可,那么从x[k-1][j]开始到x[x.size()-1][j]都为真。

class Solution {
public:
    bool isMatch(string s, string p) {
        s=" "+s;
        p=" "+p;
        int m=s.size();
        int n=p.size();
        bool x[m][n];
        x[0][0]=true;
        for(int i=1;i<m;i++)
        {
            x[i][0]=false;
        }
        for(int j=1;j<n;j++)
        {
            if(x[0][j-1]==true&&p[j]=='*')
                x[0][j]=true;
            else x[0][j]=false;
        }
        for(int i=1;i<m;i++)
        {
            for(int j=1;j<n;j++)
            {
                if(p[j]!='*')
                {
                    if((p[j]==s[i]||p[j]=='?')&&x[i-1][j-1]==true) x[i][j]=true;
                    else x[i][j]=false;
                }
                else if(p[j]=='*')
                {
                    if(x[i][j-1]==true) x[i][j]=true;
                    else if(x[i-1][j]==true) x[i][j]=true;
                    else x[i][j]=false;
                }
            }
        }
        return x[m-1][n-1];
    }
};

 

Go基础:Go语言详细介绍,环境搭建,及第一个程序详解 Go语言是Google开发的开源编程语言,具有高效、简洁、并发性强等特点。文章从Go语言的诞生背景、核心特性及应用领域展开介绍,并详细说明了Windows、Linux和macOS下的环境搭建步骤,包括安装、环境变量配置及测试方法。最后通过“Hello, World!”程序解析Go语言基本语法,并演示了编译发布和跨平台编译功能。全文涵盖了Go语言从入门到实践的完整流程,适合初学者快速上手。 阅读详情

相关推荐

openEuler系统下安装Google Chrome浏览器全攻略(附依赖问题解决方案)

本文详细介绍了在openEuler系统上安装Google Chrome浏览器的完整指南,包括环境准备、多种安装方式、依赖问题解决方案及性能优化技巧。针对openEuler特有的软件生态和依赖管理机制,提供了实用的命令和配置方法,帮助用户克服安装过程中的常见障碍,实现流畅的Chrome使用体验。

hadoop5ranger的博客 1148

【LeetCode】解题44:Wildcard Matching(动态规划解法)

LeetCode解题 44:Wildcard Matching(动态规划解法)Problem 44: Wildcard Matching [Hard]解题思路Solution (Java) Problem 44: Wildcard Matching [Hard] Given an input string (s) and a pattern (p), implement wildcard patt...

Fayedily的博客 435

SAR ADC和sigma delta ADC的区别

0、ADC基本概念 ADC,即analog to digital converter,模拟到数字的转换器,简称模数转换器。 为什么需要ADC?因为现实的世界中,电信号是连续的,例如心电信号,或者声音信号,这些连续的信号被称为“模拟信号”。 图1:心电信号 图2:声音信号 然而这种连续的信号是无法被计算机处理的,计算机只认识0和1组成的“数字信号“。ADC就充当了这样一个桥梁,将“模拟信号”转换为计算机能识别的“数字信号”。举个例子,当前的心电电压为1.2V(实际没有这么高),ADC可能会得

长河柱天的博客 2万+

Given an input string (s) and a pattern (p), implement regular expression matching with support for

Given an input stri public boolean isMatch(String text, String pattern) { if (pattern.isEmpty()) return text.isEmpty(); boolean first_match = (!text.isEmpty() &amp;&amp; ...

lifeqiuzhi521的博客 489

DPABI实战:手把手教你处理小鼠静息态fMRI数据(从Voxel Size到SPM完整流程)

本文详细介绍了使用DPABI处理小鼠静息态fMRI数据的完整流程,从Voxel Size调整到SPM分析,涵盖预处理、质量控制和可视化等关键步骤。针对小鼠数据特有的低分辨率和信噪比问题,提供了实战建议和避坑指南,帮助研究人员高效完成数据分析。

weixin_42663213的博客 476

调整开关频率处理传导骚扰超标的系统方法

针对某产品在传导骚扰测试中660kHz频点超标问题,分析发现与DC-DC模块开关频率直接相关。通过调整模块开关频率至500kHz,使其避开标准限值严苛频段(0.53-1.8MHz),在不改变硬件设计的情况下实现测试通过。该案例表明,利用EMC标准的频率特性进行"频谱设计"比传统滤波手段更高效,建议在多模块系统中采用1:2:4等频率规划策略,从源头降低噪声耦合风险。这一频率迁移思路为EMC优化提供了新范式。

硬核科技 328

LeetCode(44):通配符匹配 Wildcard Matching(Java)

2019.5.13 #程序员笔试必备# LeetCode 从零单刷个人笔记整理(持续更新) 这道题思路基本和之前做过的正则表达式匹配一致: LeetCode(10):正则表达式匹配 Regular Expression Matching(Java) 可以用正向反向两种DP的方式实现。 传送门:通配符匹配 Given an input string (s) and a pattern §, im...

NJU_ChopinXBP的博客 391

【网络】叶脊(Spine-Leaf)网络拓扑下全三层网络设计与实践(二) - 网络规划

2. 全三层架构设计思路 采用全三层网络架构设计的出发点是: 使用尽量少的交换机高级功能,可以尽可能减少由于功能bug故障造成的问题; 使用尽量少的网络协议,以兼容不通厂商的网络设备 实现简单,易于维护,绝对可靠的路由协议; 通过控制路由来调度流量,尽量减少设备或协议的故障域; 牺牲高级功能带来的便捷,得到更高的可用性和性能; 由上述原则,本文的设计选择只使用静态路由和BGP...

因吹斯汀 1万+

[leetcode]44. Wildcard Matching

链接:https://leetcode.com/problems/wildcard-matching/description/   Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'. '?' Matches any sin...

xiaocong1990的博客 411

huggingface使用git上传model或者Dataset到HF,当然也可以上传代码,以及大文件,很哇塞!!!

huggingface使用git上传model或者Dataset到HF,当然也可以上传代码,以及大文件,很哇塞!!! 第一次使用时,需要使用设置系统全局的huggingface token,这。点击huggingface首页右上角的头像 → settings → access tokens,创建一个write权限的token,名字可以随便取。

拥抱具身智能,昇腾Ascend C 3104

指纹对抗指南:如何绕过Cloudflare与Akamai的5s盾与浏览器指纹检测

现在的CDN反爬技术虽然越来越强,但是道高一尺魔高一丈,只要掌握了指纹伪造、流量伪装、行为模拟这些核心技术,就可以绕过绝大多数的防护措施。对抗过程中要注意效率和成本的平衡,小规模爬取用Playwright+stealth最方便,大规模爬取用curl_cffi+代理池性价比最高,遇到验证码用打码平台或者自动识别服务,不需要死磕破解。本文介绍的方案已经在实战中验证过,可以绕过95%以上的Cloudflare/Akamai防护,成功率非常高。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 297

【算法】Wildcard Matching通配符匹配

文章目录题目解题思路代码实现 题目 Given an input string (s) and a pattern §, implement wildcard pattern matching with support for ‘?’ and ‘*’. ‘?’ Matches any single character. ‘*’ Matches any sequence of characters ...

无良剑&染的博客 496

CDD数据库文件制作(三)——服务配置(0x10)

根据诊断调查表进行每一步配置的详细操作,与背后逻辑解释 1.会话切换配置 1.1.根据诊断调查表进行信息提取(0x1001) 1.2.会话转换配置(0x1001) 1.3.根据诊断调查表进行信息提取(0x1002) 1.4.会话转换配置(0x1002) 1.5.根据诊断调查表进行信息提取(0x1003) 1.6.会话转换配置(0x1003) 1.7.会话切换配置完成后效果图 2.安全等级配置信息提取 2.1.安全访问配置(0x1001) 2.2.安全访问配置(0x1002) 2.3.安全访问配置(0x100

LOVE135149的博客 5838

【一天一道LeetCode】#44. Wildcard Matching

一天一道LeetCode系列(一)题目 Implement wildcard pattern matching with support for ‘?’ and ‘*’. ‘?’ Matches any single character. ‘*’ Matches any sequence of characters (including the empty sequ

ZeeCoder 1179

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

[ LeetCode ]#44. Wildcard Matching(通配符匹配)

题目:44. 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...

xn's blog 210

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

【LeetCode】#44通配符匹配(Wildcard Matching)

【LeetCode】#44通配符匹配(Wildcard Matching) 题目描述 给定一个字符串 (s) 和一个字符模式 § ,实现一个支持 ‘?’ 和 ‘’ 的通配符匹配。 ‘?’ 可以匹配任何单个字符。 '’ 可以匹配任意字符串(包括空字符串)。 两个字符串完全匹配才算匹配成功。 说明: s 可能为空,且只包含从 a-z 的小写字母。 p 可能为空,且只包含从 a-z 的小写字母,以及字符...

weixin_43858604的博客 170

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

[LeetCode] #44 Wildcard Matching

mplement wildcard pattern matching with support for'?'and'*'. '?' Matches any single character. '*' Matches any sequence of characters (including the empty sequence). The matching should cover...

weixin_30950887的博客 82

Wildcard Matching_Leetcode_#44

1 题目 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

LittleBob180的专栏 373

Leetcode 44. Wildcard Matching 通配符匹配

Leetcode 44. Wildcard Matching 通配符匹配 标签: Leetcode 题目地址:https://leetcode-cn.com/problems/wildcard-matching/ 题目描述 给定一个字符串 (s) 和一个字符模式 (p) ,实现一个支持 '?' 和 '*' 的通配符匹配。 '?' 可以匹...

CoderWangSon 306

【LeetCode】44. Wildcard Matching 解题报告(Python)

题目分析: 这个题又是做类似正则匹配的,和【LeetCode】10. Regular Expression Matching基本一致。我们采用动态规划解决,创建状态数组dp然后分别判断是*怎么处理,或者是?怎么处理,详见测试代码。 测试代码: class Solution: def isMatch(self, s, p): m, n = len(s), len(p) ...

L141210113的专栏 1854

★leetcode44_Wildcard Matching

一.问题描述 Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. '*' Matches any sequence of characters (including the empty sequence). The matching sh

越努力越幸运 544

leetcode 10 Regular Expression Matching & 44 Wildcard Matching

leetcode中的两个 正则表达式匹配

ghoshorn的专栏 733

44. Wildcard Matching Leetcode Python

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 t

hyperbolechi的专栏 1596

44. Wildcard Matching leetcode Python 2016 new season

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 t

hyperbolechi的专栏 1013

leetcode-10 Regular Expression Matching & leetcode-44 Wildcard Matching

leetcode-10 Regular Expression Matching 正则表达式匹配 Given an input string (s) and a pattern (p), implement regular expression matching with support for'.'and'*'. '.' Matches any single cha...

weixin_43107805的博客 316

[Leetcode][Python]44:Wildcard Matching

# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'44:Wildcard Matchinghttps://oj.leetcode.com/problems/wildcard-matching/'?' Matches any single character.'*' Matches any sequence of cha...

aaron7909的博客 219
上一篇: LeetCode #41 - First Missing Positive
下一篇: LeetCode #58 - Length of Last Word
LawFile
博客等级 码龄10年 5粉丝 627原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值