当前位置:网站首页>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
边栏推荐
猜你喜欢

Huawei machine learning service speech recognition function enables applications to paint "sound" and color

js监听页面或元素scroll事件,滚动到底部或顶部

国内有哪些好的智能家居品牌支持homekit?

我的为人处事真的有问题吗?

Tiktok practice ~ project associated unicloud

Spark's wide dependence and narrow dependence yyds dry goods inventory

Understanding openstack network

Yyds dry goods counting uses xshell to implement agent function

Today's sleep quality record 79 points

Morris traverse
随机推荐
The R language uses the matchit package for propensity matching analysis and match The data function constructs the matched sample set, and judges the balance of all covariates in the sample after the
Yyds dry goods counting uses xshell to implement agent function
Using external Libpcap library on ARM platform
Hello C (IV) -- pointer and function
Common regular expressions
抖音实战~项目关联UniCloud
还在用 SimpleDateFormat 做时间格式化?小心项目崩掉
Redis source code analysis skip list
Spark's wide dependence and narrow dependence yyds dry goods inventory
7-8 ladder cloud vertical
2021-2022 China's financial digitalization "new" insight Industry Research Report
Printf redirection of serial port under sw4stm32 (SW4)
Actipro WPF Controls 2022.1.2
22map introduction and API
Monotone stack and its application
QT cannot be edited with UTF-8
Using ADC to control brushless motor source program STM32 library function
Andersen global strengthens the Middle East platform with Palestinian member companies
Jetpack Compose 最新进展
go 语言指针,值引用和指针引用