当前位置:网站首页>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
边栏推荐
- Cf:a. the third three number problem
- Yyds dry goods inventory # solve the real problem of famous enterprises: move the round table
- It's too convenient. You can complete the code release and approval by nailing it!
- ASEMI整流桥HD06参数,HD06图片,HD06应用
- 聊聊异步编程的 7 种实现方式
- go 指针
- Word document injection (tracking word documents) incomplete
- RHCSA9
- Halcon template matching actual code (I)
- 函数的默认参数&函数参数的多种方法
猜你喜欢

Android本地Sqlite数据库的备份和还原

Asemi rectifier bridge hd06 parameters, hd06 pictures, hd06 applications

Write API documents first or code first?

MySQL --- 数据库查询 - 排序查询、分页查询

CAN和CAN FD

Datapipeline was selected into the 2022 digital intelligence atlas and database development report of China Academy of communications and communications

DataPipeline双料入选中国信通院2022数智化图谱、数据库发展报告

The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched

A specific example of ABAP type and EDM type mapping in SAP segw transaction code

ASEMI整流桥HD06参数,HD06图片,HD06应用
随机推荐
[daily question] 1200 Minimum absolute difference
APICloud Studio3 WiFi真机同步和WiFi真机预览使用说明
Natural language processing series (I) introduction overview
go 指针
FPGA 学习笔记:Vivado 2019.1 添加 IP MicroBlaze
leetcode:221. Maximum square [essence of DP state transition]
SAP UI5 DynamicPage 控件介紹
实现 1~number 之间,所有数字的加和
Introduction to sap ui5 dynamicpage control
DataPipeline双料入选中国信通院2022数智化图谱、数据库发展报告
【Hot100】34. 在排序数组中查找元素的第一个和最后一个位置
Go array and slice
Get to know linkerd project for the first time
今年上半年,通信行业发生了哪些事?
Pandora IOT development board learning (HAL Library) - Experiment 7 window watchdog experiment (learning notes)
峰会回顾|保旺达-合规和安全双驱动的数据安全整体防护体系
Put functions in modules
Pycharm installation third party library diagram
How to protect user privacy without password authentication?
UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xe6 in position 76131: invalid continuation byt