当前位置:网站首页>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
边栏推荐
- 求组合数 AcWing 889. 满足条件的01序列
- Play with the cluster configuration center and learn about the Taier console
- NFT leaderboard -nft real offer latest address: NFT leaderboard.com
- 高斯消元 AcWing 884. 高斯消元解异或线性方程组
- ACM warm-up Exercise 2 in 2022 summer vacation (summary)
- 求组合数 AcWing 887. 求组合数 III
- Error: image clipToBoundsAndScale, argument 'input'
- 11 wrong set
- Thank you for your likes and attention
- Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.
猜你喜欢
随机推荐
ethereum rpc
树形DP AcWing 285. 没有上司的舞会
11 wrong set
洛谷P1896 互不侵犯
Wilderness search --- search iterations
涌现与形态的局部差异和整体差异
推导重叠积分的详细展开式 STO overlap integrals
高斯消元 AcWing 883. 高斯消元解线性方程组
Miscellaneous records of Finance
Real time development platform construction practice, in-depth release of real-time data value - 04 live broadcast review
How to assemble a registry
Derive the detailed expansion of STO double center kinetic energy integral
IO stream_ Overview and explanation of data input and output flow
Wechat push - template message parameter configuration
发动机悬置系统冲击仿真-瞬时模态动态分析与响应谱分析
如何组装一个注册中心
9 UAV array
栈 AcWing 3302. 表达式求值
What changes will metauniverse bring to the music industry in the trillion market?
C language 2: find the maximum value of three numbers, find the middle value of three numbers, and write program steps







