当前位置:网站首页>LeetCode 10. Regular Expression Matching
LeetCode 10. Regular Expression Matching
2022-07-22 01:25:00 【HumbleFool】
LeetCode 10. Regular Expression Matching
Dynamic programming
const int N = 25, M = 35;
class Solution {
public:
bool f[N][M] = {
false}; // s front i And p front j matching
bool isMatch(string s, string p) {
int n = s.size(), m = p.size();
s = " " + s, p = " " + p;
// Initialization conditions , Only the last character is * Can match only when
f[0][0] = true;
for(int i = 1; i <= m; i ++)
if(p[i] == '*')
f[0][i] = f[0][i - 2];
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
{
if(j + 1 <= m && p[j + 1] == '*') continue;
if(p[j] != '*') // No * And matching
f[i][j] = f[i - 1][j - 1] &&(s[i] == p[j] || p[j] == '.');
if(p[j] == '*') // yes *, And divided into representatives 1 Characters , Two characters , Three characters ....
f[i][j] = f[i][j - 2] || f[i - 1][j] && (s[i] == p[j - 1] || p[j - 1] == '.');
}
return f[n][m];
}
};
边栏推荐
猜你喜欢
随机推荐
The classification of artificial neural network includes: the classification of artificial neural network includes
近红外染料CY7.5标记PNA多肽实验步骤CY7.5-PNA|188Re标记反基因肽核酸(AGPNA)
Visualization: you must know these ten data visualization tool software platforms
Oracle笔记 之 空值null的处理
Software resources Encyclopedia
[daily training] 1260 2D mesh migration
Appium脚本启动参数如何设置
Pipeline operators in mongodb ($group, $unwind, $sort, $limit, $skip)
docker搭建redis及集群
LeetCode 10. 正则表达式匹配
查看IAR工程所用版本号
Statistics for each month of the year
How to understand pointers?
token和session的区别,这个经典面试题值得一个更深入的回答
mysql数据恢复
Lecture 1 Overview
数据库连接池
47: Chapter 4: developing file services: 8: automatic image review (Alibaba cloud content security); (don't read it if you haven't written it yet; to be written...)
“我放弃编程,写了一本130万字的硬科幻小说”
[rm_ee_note] 2 serial port & remote control