当前位置:网站首页>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
边栏推荐
- Go array and slice
- 蜀天梦图×微言科技丨达梦图数据库朋友圈+1
- Changing JS code has no effect
- ##无监控,不运维,以下是监控里常用的脚本监控
- [notes of in-depth study paper]uctransnet: rethink the jumping connection in u-net from the perspective of transformer channel
- [daily question] 1200 Minimum absolute difference
- 先写API文档还是先写代码?
- CF:A. The Third Three Number Problem【关于我是位运算垃圾这个事情】
- Lb10s-asemi rectifier bridge lb10s
- Flutter 绘制波浪移动动画效果,曲线和折线图
猜你喜欢
潘多拉 IOT 开发板学习(HAL 库)—— 实验7 窗口看门狗实验(学习笔记)
【每日一题】1200. 最小绝对差
《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
《2022年中國銀行業RPA供應商實力矩陣分析》研究報告正式啟動
Although the volume and price fall, why are the structural deposits of commercial banks favored by listed companies?
OpenHarmony应用开发之Navigation组件详解
Shandong University Summer Training - 20220620
[深度学习论文笔记]UCTransNet:从transformer的通道角度重新思考U-Net中的跳跃连接
解决uni-app配置页面、tabBar无效问题
Actual combat simulation │ JWT login authentication
随机推荐
Write macro with word
MySQL 巨坑:update 更新慎用影响行数做判断!!!
Datapipeline was selected into the 2022 digital intelligence atlas and database development report of China Academy of communications and communications
Discussion on error messages and API versions of SAP ui5 getsaplogonlanguage is not a function
MySQL splits strings for conditional queries
什么是网络端口
Android本地Sqlite数据库的备份和还原
先写API文档还是先写代码?
LB10S-ASEMI整流桥LB10S
解决uni-app配置页面、tabBar无效问题
leetcode:221. Maximum square [essence of DP state transition]
Pandora IOT development board learning (HAL Library) - Experiment 7 window watchdog experiment (learning notes)
Run, open circuit
go map
Lb10s-asemi rectifier bridge lb10s
个人组件 - 消息提示
CF:A. The Third Three Number Problem【关于我是位运算垃圾这个事情】
Go pointer
Concurrent performance test of SAP Spartacus with JMeter
AVC1与H264的区别