当前位置:网站首页>Leetcode skimming ---10
Leetcode skimming ---10
2022-07-03 10:35:00 【Long time no see 0327】
subject : Given a string s And a character rule p, Implement a support '.' and '*' Regular expression matching .
- '.' Match any single character
- '*' Match zero or more previous elements
Match , Is to cover Whole string s Of , Instead of partial strings .
Input :s = "aa", p = "a"
Output :false
Method 1 : Regular Expression Matching
class Solution {
public:
bool isMatch(string s, string p) {
int m = s.size();
int n = p.size();
auto matches = [&](int i, int j) {
if (i == 0) {
return false;
}
if (p[j - 1] == '.') {
return true;
}
return s[i - 1] == p[j - 1];
};
vector<vector<int>> f(m+1, vector<int>(n + 1));
f[0][0] = true;
for (int i = 0; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
if (p[j - 1] == '*') {
f[i][j] |= f[i][j-2];
if (matches(i, j-1)) {
f[i][j] |= f[i-1][j];
}
} else {
if (matches(i, j)) {
f[i][j] |= f[i-1][j-1];
}
}
}
}
return f[m][n];
}
};Complexity analysis
Time complexity :O(mn)
Spatial complexity :O(mn)
边栏推荐
- [LZY learning notes -dive into deep learning] math preparation 2.1-2.4
- 20220601数学:阶乘后的零
- Leetcode-106: construct a binary tree according to the sequence of middle and later traversal
- CSDN, I'm coming!
- Matrix calculation of Neural Network Introduction (pytoch)
- Preliminary knowledge of Neural Network Introduction (pytorch)
- Leetcode刷题---283
- Automatic derivation of introduction to deep learning (pytoch)
- Introduction to deep learning linear algebra (pytorch)
- Hands on deep learning pytorch version exercise solution - 2.4 calculus
猜你喜欢
![[C question set] of Ⅵ](/img/49/eb31cd26f7efbc4d57f17dc1321092.jpg)
[C question set] of Ⅵ

多层感知机(PyTorch)

Data preprocessing - Data Mining 1

Hands on deep learning pytorch version exercise solution - 2.5 automatic differentiation

丢弃法Dropout(Pytorch)

深度学习入门之线性回归(PyTorch)

Knowledge map reasoning -- hybrid neural network and distributed representation reasoning

Standard library header file

High imitation wechat

Simple real-time gesture recognition based on OpenCV (including code)
随机推荐
Inverse code of string (Jilin University postgraduate entrance examination question)
Hands on deep learning pytorch version exercise solution - 3.1 linear regression
二分查找法
Policy gradient Method of Deep Reinforcement learning (Part One)
Rewrite Boston house price forecast task (using paddlepaddlepaddle)
波士顿房价预测(TensorFlow2.9实践)
2018 Lenovo y7000 black apple external display scheme
Leetcode刷题---367
Leetcode刷题---1
20220607其他:两整数之和
【毕业季】图匮于丰,防俭于逸;治不忘乱,安不忘危。
Data preprocessing - Data Mining 1
Label Semantic Aware Pre-training for Few-shot Text Classification
神经网络入门之预备知识(PyTorch)
ECMAScript -- "ES6 syntax specification # Day1
Numpy Foundation
实战篇:Oracle 数据库标准版(SE)转换为企业版(EE)
Several problems encountered in installing MySQL under MAC system
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow
多层感知机(PyTorch)