当前位置:网站首页>leetcode 10. Regular expression matching regular expression matching (difficult)
leetcode 10. Regular expression matching regular expression matching (difficult)
2022-07-05 13:18:00 【InfoQ】
One 、 The main idea of the topic
- 1 <= s.length <= 20
- 1 <= p.length <= 30
- s Only from a-z Lowercase letters of .
- p Only from a-z Lowercase letters of , As well as the character . and *.
- Ensure that characters appear every time * when , All of them are matched with valid characters
Two 、 Their thinking
3、 ... and 、 How to solve the problem
3.1 Java Realization
public class Solution2 {
public boolean isMatch(String s, String p) {
int m = s.length();
int n = p.length();
boolean[][] dp = new boolean[m + 1][n + 1];
dp[0][0] = true;
for (int i = 1; i < n + 1; i++) {
if (p.charAt(i - 1) == '*') {
// asterisk Not on page 1 A place
dp[0][i] = dp[0][i - 2];
}
}
for (int i = 1; i < m + 1; i++) {
for (int j = 1; j < n + 1; j++) {
// The last wildcard may be Order number 、 asterisk 、 character
if (p.charAt(j - 1) == '.') {
// The last wildcard is Order number
dp[i][j] = dp[i - 1][j - 1];
} else if (p.charAt(j - 1) != '*') {
// The last wildcard is not asterisk
dp[i][j] = dp[i - 1][j - 1] && p.charAt(j - 1) == s.charAt(i - 1);
} else if (p.charAt(j - 2) != s.charAt(i - 1) && p.charAt(j - 2) != '.') {
dp[i][j] = dp[i][j - 2];
} else {
dp[i][j] = dp[i][j - 1] || dp[i - 1][j] || dp[i][j - 2];
}
}
}
return dp[m][n];
}
}
Four 、 Summary notes
- 2022/7/5 people follow the example of their superiors , The emperor's new dress
边栏推荐
- Association modeling method in SAP segw transaction code
- FPGA 学习笔记:Vivado 2019.1 添加 IP MicroBlaze
- How to protect user privacy without password authentication?
- Go array and slice
- 155. 最小栈
- Get to know linkerd project for the first time
- Backup and restore of Android local SQLite database
- Hiengine: comparable to the local cloud native memory database engine
- CloudCompare——点云切片
- 函数的默认参数&函数参数的多种方法
猜你喜欢
解决uni-app配置页面、tabBar无效问题
leetcode:221. 最大正方形【dp状态转移的精髓】
量价虽降,商业银行结构性存款为何受上市公司所偏爱?
jenkins安装
峰会回顾|保旺达-合规和安全双驱动的数据安全整体防护体系
MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!
山东大学暑期实训一20220620
Talk about seven ways to realize asynchronous programming
Flutter draws animation effects of wave movement, curves and line graphs
How to protect user privacy without password authentication?
随机推荐
APICloud Studio3 WiFi真机同步和WiFi真机预览使用说明
Le rapport de recherche sur l'analyse matricielle de la Force des fournisseurs de RPA dans le secteur bancaire chinois en 2022 a été officiellement lancé.
[daily question] 1200 Minimum absolute difference
About the single step debugging of whether SAP ui5 floating footer is displayed or not and the benefits of using SAP ui5
[notes of in-depth study paper]uctransnet: rethink the jumping connection in u-net from the perspective of transformer channel
C# 对象存储
蜀天梦图×微言科技丨达梦图数据库朋友圈+1
Small case of function transfer parameters
Association modeling method in SAP segw transaction code
SAP UI5 DynamicPage 控件介紹
Changing JS code has no effect
STM32 and motor development (from architecture diagram to documentation)
SAP ui5 objectpagelayout control usage sharing
Shuttle INKWELL & ink components
Fragmented knowledge management tool memos
155. 最小栈
Hundred days to complete the open source task of the domestic database opengauss -- openguass minimalist version 3.0.0 installation tutorial
jenkins安装
Talking about fake demand from takeout order
【服务器数据恢复】某品牌服务器存储raid5数据恢复案例