当前位置:网站首页>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
边栏推荐
- 推导STO双中心动能积分的详细展开式
- 计算重叠积分的第二种方法
- 洛谷 P3052 [USACO12MAR]Cows in a Skyscraper G
- [FPGA tutorial case 40] communication case 10 -- Verilog implementation of a simple OFDM system based on FPGA
- Wechat push - template message parameter configuration
- 2022 Niuke multi school training (3) a-ancestor topic translation
- 9 UAV array
- Miscellaneous records of Finance
- 发动机悬置系统冲击仿真-瞬时模态动态分析与响应谱分析
- properties文件
猜你喜欢

背包模型 AcWing 1022. 宠物小精灵之收服

How to build a data index system is the most effective. From 0 to 1, we will take you a quick start - 02 live review

KEPServer配置

发动机悬置系统冲击仿真-瞬时模态动态分析与响应谱分析

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

Opengauss kernel analysis - statistics and row count estimation

背包模型 AcWing 1024. 装箱问题

How to create a.Net image with diagnostic tools

ethereum rpc

FAQs of "relay chain" and "dot" in Poka ecosystem
随机推荐
4 search insertion location
如何创建一个带诊断工具的.NET镜像
Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing
15th largest value of data flow
Remember not to copy your group work, students. Fortunately, you only passed two questions. Don't have an accident
What changes will metauniverse bring to the music industry in the trillion market?
Wenzhou University X kangaroo cloud: how to "know well" in the construction of higher talent education
求组合数 AcWing 887. 求组合数 III
黑白像素分布对迭代次数的影响
熵与形态的非递进现象
洛谷P1441 砝码称重
2022牛客多校训练(3)A-Ancestor 题目翻译
Yonbuilder enables innovation, and the "golden keyboard Award" of the fourth UFIDA developer competition is open!
Longest ascending subsequence model acwing 1010. Interceptor missile
PAT(乙级)2022年夏季考试
洛谷P1896 互不侵犯
背包模型 AcWing 1024. 装箱问题
ACM warm-up Exercise 1 in 2022 summer vacation (summary)
The influence of the number of non-zero values in the picture on Classification
如何组装一个注册中心