当前位置:网站首页>Force buckle - 10. Regular expression matching
Force buckle - 10. Regular expression matching
2022-07-27 11:18:00 【weixin_ fifty-four million ninety-six thousand two hundred and 】
1. subject
2. Ideas
First string s.length()>0, Or judge s.isEmpty();
It can be done in two steps , The first part mainly discusses the possibility of the first regular symbol , utilize &&,|| expression
situation 1: It could be a character , Look at the second symbol ;pattern.charAt(0)==text.charAt(0);
situation 2: If it is ".", You also need to see the second character ;pattern.charAt(0)=='.'
The second part is to consider the possibility of the second character .(pattern.length()>2)
situation 1: If the second character is “*”(pattern.charAt(1)=='*'), Then judge whether the character of the first regular expression is . Or characters . utilize isMatch Function to match first_match && isMatch(text.substring(1),pattern)
situation 2: If not “*”, See if it's with text The text matches first_match&&isMatch(pattern.substring(1),text.substring(1))
3. Code
public class Solution {
public boolean isMatch(String text, String pattern) {
if(pattern.isEmpty()) return text.isEmpty();
boolean first_match=(!text.isEmpty() &&(pattern.charAt(0) == text.charAt(0) || pattern.charAt(0)=='.'));
if(pattern.length()>=2 && pattern.charAt(1)=='*'){
return (isMatch(text,pattern.substring(2))||
(first_match && isMatch(text.substring(1),pattern)));
}
else{
return first_match&&isMatch(pattern.substring(1),text.substring(1));
}
}
}Reference link :(101 Bar message ) LeetCode:10 Regular Expression Matching (Java)_INC Follow my blog -CSDN Blog
边栏推荐
- IMG SRC is empty or SRC does not exist, and the picture has a white border
- 2022 Niuke multi school training (3) a-ancestor topic translation
- 10 complete half of the questions
- Use of parsel
- 最长上升子序列模型 AcWing 1014. 登山
- JVM judges that the object is dead, and practices verify GC recycling
- SQL Server2000 database error
- 2022 Niuke multi school (3) j.journey
- Thank you for your likes and attention
- Students, don't copy all my code, remember to change it, or we both want G
猜你喜欢

IMG SRC is empty or SRC does not exist, and the picture has a white border

MySQL installation (RPM package)

解决 ImportError: cannot import name 'abs' 导入tensorflow报错

The difference of iteration number and information entropy

Use of pyquery

数字三角形模型 AcWing 275. 传纸条

数字三角形模型 AcWing 1015. 摘花生

Opengauss kernel analysis - statistics and row count estimation

栈 AcWing 3302. 表达式求值

49 letter ectopic grouping and 242 effective letter ectopic words
随机推荐
Asustek unparalleled, this may be the best affordable high brush thin notebook on the screen
Budweiser, a well-known beer, plans to launch NFT in an attempt to unveil the "long planned" uplink?
洛谷P1896 互不侵犯
深析C语言的灵魂 -- 指针
Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing
IO流_数据输入输出流的概述和讲解
15th largest value of data flow
Play with the cluster configuration center and learn about the Taier console
SQL Server2000数据库错误
Digital triangle model acwing 275. pass note
Why is the data service API the standard configuration of the data midrange when we take the last mile of the data midrange?
SQL Server2000 database error
An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
The longest ascending subsequence model acwing 1016. The sum of the largest ascending subsequence
Luogu p1896 non aggression
Wilderness search --- search iterations
求组合数 AcWing 887. 求组合数 III
Longest ascending subsequence model acwing 482. Chorus formation
FAQs of "relay chain" and "dot" in Poka ecosystem
What changes will metauniverse bring to the music industry in the trillion market?