当前位置:网站首页>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
边栏推荐
- jenkins安装
- Changing JS code has no effect
- 函数传递参数小案例
- Pandora IOT development board learning (HAL Library) - Experiment 7 window watchdog experiment (learning notes)
- FPGA 学习笔记:Vivado 2019.1 添加 IP MicroBlaze
- 《2022年中國銀行業RPA供應商實力矩陣分析》研究報告正式啟動
- #从源头解决# 自定义头文件在VS上出现“无法打开源文件“XX.h“的问题
- mysql econnreset_ Nodejs socket error handling error: read econnreset
- PyCharm安装第三方库图解
- Shu tianmeng map × Weiyan technology - Dream map database circle of friends + 1
猜你喜欢
![[deep learning paper notes] hnf-netv2 for segmentation of brain tumors using multimodal MR imaging](/img/52/5e85743b1817de96a52e02b92fd08c.png)
[deep learning paper notes] hnf-netv2 for segmentation of brain tumors using multimodal MR imaging

Leetcode20. Valid parentheses

CF:A. The Third Three Number Problem【关于我是位运算垃圾这个事情】

“百度杯”CTF比赛 九月场,Web:SQL

Get to know linkerd project for the first time

Binder通信过程及ServiceManager创建过程

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

一文详解ASCII码,Unicode与utf-8

Detailed explanation of navigation component of openharmony application development

Hiengine: comparable to the local cloud native memory database engine
随机推荐
简单上手的页面请求和解析案例
jenkins安装
Hiengine: comparable to the local cloud native memory database engine
#yyds干货盘点# 解决名企真题:搬圆桌
Realize the addition of all numbers between 1 and number
155. Minimum stack
CloudCompare——点云切片
Rocky basic command 3
函数传递参数小案例
阿里云SLB负载均衡产品基本概念与购买流程
【Hot100】34. Find the first and last positions of elements in a sorted array
Backup and restore of Android local SQLite database
leetcode:221. Maximum square [essence of DP state transition]
APICloud Studio3 WiFi真机同步和WiFi真机预览使用说明
leetcode 10. Regular Expression Matching 正则表达式匹配 (困难)
JS to determine whether an element exists in the array (four methods)
Run, open circuit
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é.
[deep learning paper notes] hnf-netv2 for segmentation of brain tumors using multimodal MR imaging
Simple page request and parsing cases