当前位置:网站首页>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
边栏推荐
- 使用Dom4j解析XML
- uni-app开发语音识别app,讲究的就是简单快速。
- Notion 类笔记软件如何选择?Notion 、FlowUs 、Wolai 对比评测
- C# 对象存储
- RHCSA9
- [深度学习论文笔记]TransBTSV2: Wider Instead of Deeper Transformer for Medical Image Segmentation
- [深度学习论文笔记]使用多模态MR成像分割脑肿瘤的HNF-Netv2
- AVC1与H264的区别
- Rocky basic command 3
- [深度学习论文笔记]UCTransNet:从transformer的通道角度重新思考U-Net中的跳跃连接
猜你喜欢

Introduction to sap ui5 dynamicpage control

CAN和CAN FD

Go array and slice

Get to know linkerd project for the first time

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

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

MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!

Principle and performance analysis of lepton lossless compression

【服务器数据恢复】某品牌服务器存储raid5数据恢复案例

数据湖(七):Iceberg概念及回顾什么是数据湖
随机推荐
Hundred days to complete the open source task of the domestic database opengauss -- openguass minimalist version 3.0.0 installation tutorial
[深度学习论文笔记]使用多模态MR成像分割脑肿瘤的HNF-Netv2
函数传递参数小案例
Realize the addition of all numbers between 1 and number
There is no monitoring and no operation and maintenance. The following is the commonly used script monitoring in monitoring
js判断数组中是否存在某个元素(四种方法)
Sorry, we can't open xxxxx Docx, because there is a problem with the content (repackaging problem)
JS to determine whether an element exists in the array (four methods)
[daily question] 1200 Minimum absolute difference
FPGA 学习笔记:Vivado 2019.1 添加 IP MicroBlaze
一文详解ASCII码,Unicode与utf-8
个人组件 - 消息提示
爱可生SQLe审核工具顺利完成信通院‘SQL质量管理平台分级能力’评测
精彩速递|腾讯云数据库6月刊
Solve Unicode decodeerror: 'GBK' codec can't decode byte 0xa2 in position 107
RHCSA10
使用Dom4j解析XML
Datapipeline was selected into the 2022 digital intelligence atlas and database development report of China Academy of communications and communications
Principle and configuration of RSTP protocol
Apicloud studio3 API management and debugging tutorial