当前位置:网站首页>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)
边栏推荐
- Class-Variant Margin Normalized Softmax Loss for Deep Face Recognition
- Realize an online examination system from zero
- Data classification: support vector machine
- [LZY learning notes -dive into deep learning] math preparation 2.1-2.4
- Label Semantic Aware Pre-training for Few-shot Text Classification
- 20220608 other: evaluation of inverse Polish expression
- Leetcode刷题---44
- 20220601 Mathematics: zero after factorial
- Multi-Task Feature Learning for Knowledge Graph Enhanced Recommendation
- 丢弃法Dropout(Pytorch)
猜你喜欢

权重衰退(PyTorch)

Stroke prediction: Bayesian

Multi-Task Feature Learning for Knowledge Graph Enhanced Recommendation

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

C#项目-寝室管理系统(1)

Yolov5 creates and trains its own data set to realize mask wearing detection

Softmax 回归(PyTorch)

Matrix calculation of Neural Network Introduction (pytoch)

LeetCode - 900. RLE iterator

Powshell's set location: unable to find a solution to the problem of accepting actual parameters
随机推荐
Ind kwf first week
What did I read in order to understand the to do list
Multi-Task Feature Learning for Knowledge Graph Enhanced Recommendation
侯捷——STL源码剖析 笔记
【SQL】一篇带你掌握SQL数据库的查询与修改相关操作
Simple real-time gesture recognition based on OpenCV (including code)
Knowledge map enhancement recommendation based on joint non sampling learning
ThreadLocal原理及使用场景
GAOFAN Weibo app
神经网络入门之模型选择(PyTorch)
Preliminary knowledge of Neural Network Introduction (pytorch)
Ind FHL first week
R language classification
ECMAScript -- "ES6 syntax specification # Day1
Are there any other high imitation projects
Raspberry pie 4B installs yolov5 to achieve real-time target detection
20220601数学:阶乘后的零
【毕业季】图匮于丰,防俭于逸;治不忘乱,安不忘危。
Adaptive Propagation Graph Convolutional Network
20220604 Mathematics: square root of X