当前位置:网站首页>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;
}
};
边栏推荐
- ssm练习第二天_项目拆分moudle_基本增删改查_批量删除_一对一级联查询
- Zhaoqi science and technology innovation overseas high-level talent introduction platform, entrepreneurship event Roadshow
- 2020美亚个人赛复盘
- [training day3] section
- 成为测试/开发程序员,小张:现实就来了个下马威......
- Cross site scripting attack (XSS)
- PMP Exam details, what changes have been made to the new exam outline?
- 网易游戏研发工程师实习生(客户端方向)一面
- 老子云携手福昕鲲鹏,首次实现3D OFD三维版式文档的重大突破
- 5、 Parameter server principle, code implementation
猜你喜欢

Vector CANoe Menu Plugin拓展入门

面试OPPO,16道题甩过来,我人傻了

It is said that the salary of Alibaba P7 is really fragrant

AI zhetianchuan ml unsupervised learning

Deep learning experiment: softmax realizes handwritten digit recognition

CentOS installs docker and MySQL and redis environments

Data warehouse: fact table of detailed dimensional modeling
![[unity3d] rocker](/img/b7/40643a2676b251c185ce58840f7581.png)
[unity3d] rocker

BulletGraph(子弹图、项目符号图)

Become a test / development programmer, Xiao Zhang: reality is coming
随机推荐
Leetcode 50 day question brushing plan (day 4 - longest palindrome substring 14.00-16:20)
Data warehouse: fact table of detailed dimensional modeling
LeetCode50天刷题计划(Day 3—— 串联所有单词的子串 10.00-13.20)
PS_ 2_ layer
Cross site scripting attack (XSS)
中国聚异丁烯市场研究与投资价值报告(2022版)
Relative path and absolute path
《敏捷宣言》四大价值观,十二大原则
百度飞桨EasyDL X 韦士肯:看轴承质检如何装上“AI之眼”
Zhaoqi science and technology innovation overseas high-level talent introduction platform, entrepreneurship event Roadshow
[training Day1] Dwaves line up
[unity3d] rocker
[Digital IC] understand Axi Lite protocol in simple terms
Become a test / development programmer, Xiao Zhang: reality is coming
[training day3] delete
常用api
2022年的PMP考试大纲是什么?
Linux安装mysql8.0.29详细教程
Bulletgraph (bullet diagram, bullet diagram)
Drools basic grammar