当前位置:网站首页>Sword finger offer regular expression matching
Sword finger offer regular expression matching
2022-07-26 18:21:00 【Morita Rinko】
Regular Expression Matching
Subject requirements :
Please implement a function to match including ’.‘ and ’‘ Regular expression of .
1. Characters in pattern ’.‘ Represents any character
2. Characters in pattern ’' Indicates that the character in front of it can appear any number of times ( contain 0 Time ).
In the subject , Matching means that all characters of a string match the whole pattern . for example , character string "aaa" With the model "a.a" and "abaca" matching , But with the "aa.a" and "ab*a" No match 
Solution code :
class Solution {
public:
/**
* The class name in the code 、 Method name 、 The parameter name has been specified , Do not modify , Return the value specified by the method directly
*
*
* @param str string character string
* @param pattern string character string
* @return bool Boolean type
*/
bool match(string str, string pattern) {
return MyMath(str, 0, pattern, 0);
}
// use i,j To indicate whether the subscript is better to judge whether it is out of bounds
bool MyMath(string str,int i,string patten,int j){
// If str Traverse complete ,patten If the traversal is just completed , Indicates that the match is successful
if(i>=str.size() && j==patten.size()){
return true;
}
// If str No traversal completed , however patten After traversal , Description matching failed
if(i<str.size() && j>=patten.size()){
return false;
}
//patten The suffix is *
if(patten[j+1]=='*' && (j+1)<patten.size()){
//str and patten If the match is successful
if(i<str.size() && (str[i]==patten[j] || patten[j]=='.')){
return (MyMath(str, i+1, patten, j) || MyMath(str, i, patten, j+2));
}else{
return MyMath(str, i, patten, j+2);
}
}
if((str[i]==patten[j] || patten[j]=='.') && i<str.size()){
return MyMath(str, i+1, patten, j+1);
}
return false;
}
};
边栏推荐
- Leetcode 50 day question brushing plan (day 2 - the longest substring without repeated characters 10.00-12.00)
- 数据仓库:详解维度建模之事实表
- 6、 Common commands of ROS (I): rosnode, rostopic, rosmsg
- Oracle第二天(视图、索引、plsql、游标、存储过程和存储函数、触发器、jdbc访问存储过程和存储函数)
- Leetcode 50 day question brushing plan (day 3 - concatenate substrings of all words 10.00-13.20)
- LeetCode50天刷题计划(Day 1—— 两数相加 11.00-12.30)
- It is said that the salary of Alibaba P7 is really fragrant
- 俄语翻译的就业前景怎样 如何做好俄语翻译工作
- [training Day2] torchbearer
- Leetcode 50 day question brushing plan (day 1 - add two numbers 11.00-12.30)
猜你喜欢
![[Digital IC] understand Axi Lite protocol in simple terms](/img/2b/15b3d831bba6aa772ad83f3ac91d23.png)
[Digital IC] understand Axi Lite protocol in simple terms

有一说一,阿里P7的薪资待遇是真的香

Leetcode 50 day question brushing plan (day 4 - longest palindrome substring 14.00-16:20)

隐私计算基础组件系列-混淆电路

俄语翻译的就业前景怎样 如何做好俄语翻译工作

PS_1_认识主界面_新建文档(分辨率)_打开保存(序列动画)
![[metauniverse OMI theory] analyze Web3 risk challenges and build Web3 ecological security](/img/d1/4a424d810f7a6aaccae80b4fe232c0.png)
[metauniverse OMI theory] analyze Web3 risk challenges and build Web3 ecological security

LeetCode50天刷题计划(Day 5—— 最长回文子串 10.50-13:00)

相对路径与绝对路径

Oracle第二天(视图、索引、plsql、游标、存储过程和存储函数、触发器、jdbc访问存储过程和存储函数)
随机推荐
8.2 some algebraic knowledge (groups, cyclic groups and subgroups)
数据仓库:详解维度建模之事实表
LeetCode50天刷题计划(Day 4—— 最长回文子串 14.00-16:20)
[Oumi reading club] talk about the creator economy in the meta universe: infinite dimension
Day 4 of SSM practice_ Get user name_ User exit_ User CRUD_ Password encryption_ Roles_ jurisdiction
PMP考试详解,新考纲有什么变化?
点云目标检测KITTI数据集bin文件可视化,一站式解决
PS_ 2_ layer
SQL determines whether a column contains Chinese characters, English characters, pure numbers, and data interception
Machine learning by Li Hongyi 2. Regression
DTS搭载全新自研内核,突破两地三中心架构的关键技术|腾讯云数据库
202. Happy number
Leetcode 50 day question brushing plan (day 5 - longest palindrome substring 10.50-13:00)
Spark data format unsafe row
网易游戏研发工程师实习生(客户端方向)一面
236. The nearest common ancestor of a binary tree
Detailed explanation of openwrt's feeds.conf.default
Point cloud target detection Kitti dataset bin file visualization, one-stop solution
8.1 Diffie-Hellman密钥交换
Quartz trigger rule