当前位置:网站首页>Leetcode No.10 regular expression matching
Leetcode No.10 regular expression matching
2022-06-24 23:45:00 【Jiangxingqi】
One 、 Title Description
Give you a string s And a character rule p, Please come to realize a support '.' and '*' Regular expression matching .
'.' Match any single character
'*' Match zero or more previous elements
Match , Is to cover Whole character string s Of , Instead of partial strings .
explain :
s May is empty , And contains only from a-z Lowercase letters of .
p May is empty , And contains only from a-z Lowercase letters of , As well as the character . and *.
Example 1:
Input :
s = "aa"
p = "a"
Output : false
explain : "a" Can't match "aa" Whole string .
Example 2:
Input :
s = "aa"
p = "a*"
Output : true
explain : because '*' Represents the element that can match zero or more preceding elements , The element in front of here is 'a'. therefore , character string "aa" Can be regarded as 'a' I repeated it once .
Example 3:
Input :
s = "ab"
p = ".*"
Output : true
explain : ".*" Means zero or more can be matched ('*') Any character ('.').
Example 4:
Input :
s = "aab"
p = "c*a*b"
Output : true
explain : because '*' Represents zero or more , here 'c' by 0 individual , 'a' Be repeated once . So you can match strings "aab".
Example 5:
Input :
s = "mississippi"
p = "mis*is*p*."
Output : false
Two 、 Ideas
First convert the string into a pointer
1、 If p It's empty ,s Null match ,s Non null mismatch ;
2、s Non empty ,p == s || p == '.' Match the first character when ;
3、(p+1) != '', Then recursively determine whether the rest match first_match && isMatch(++s, ++p)
4、(p+1) == '*', There are two matching cases :
① * matching 0 Characters ,s Match the rest , namely isMatch(s, p+2)
② * matching 1 Characters , Keep using p Match the rest s, namely first_match && isMatch(s+1, p)
3、 ... and 、 Code
边栏推荐
- 379. hide and seek
- R语言使用glm函数构建泊松对数线性回归模型处理三维列联表数据构建饱和模型、使用summary函数获取模型汇总统计信息、解读模型系数交互作用及其显著性
- Volcano成Spark默认batch调度器
- Nominal resistance table of patch resistors with 5% and 1% accuracy
- R语言dplyr包group_by函数和summarise_at函数计算dataframe计算不同分组的计数个数和均值(Summarise Data by Categorical Variable)
- Leetcode topic [array] -39- combined sum
- Hello C (two) -- use of bit operation
- 376. machine tasks
- Hello C (VI) -- pointer and string
- 7-9 寻宝路线
猜你喜欢

STM32CubeIDE SWV功能使用方法

中学校园IP网络广播系统解决方案-校园数字IP广播系统方案设计指南

Tiktok actual combat ~ sorting out the short video release process

MySQL 表的增删查改

HarmonyOS访问数据库实例(3)--用ORM Bee测下HarmonyOS到底有多牛

抖音实战~项目关联UniCloud

Solution of IP network broadcasting system in Middle School Campus - Design Guide for Campus Digital IP broadcasting system
Unveiling the secrets of the Winter Olympics | smartbi's partners supported the "front and back" of the Beijing Winter Olympics

Sword finger offer merges two sorted lists

7-6 铺设油井管道
随机推荐
Design and practice of vivo server monitoring architecture
Annual salary of millions, 7 years of testing experience: stay at a fairly good track, accumulate slowly, wait for the wind to come
QT cannot be edited with UTF-8
Enterprise level ~uni app network request encapsulation
R语言dplyr包select函数将dataframe数据中的指定数据列移动到dataframe数据列中的第一列(首列)
抖音实战~项目关联UniCloud
Redis source code analysis skip list
Tomorrow is the PMP Exam (June 25). Have you understood all this?
Volcano becomes spark default batch scheduler
7-3 最大子段和
Installing IBM CPLEX academic edition | CONDA installing CPLEX
HMS core discovery Episode 13 live broadcast Preview - building the real world in mobile games
378. Knight placement
单调栈以及单调栈的应用
Hyperledger Fabric 2. X dynamic update smart contract
257. detention of offenders
Use of types, values, namespaces, combinations, etc. in typescript
Tiktok actual combat ~ sorting out the short video release process
Printf redirection of serial port under sw4stm32 (SW4)
Hello C (I) -- basics of C language