0010. 正则表达式匹配 #85
utterances-bot
started this conversation in
Comments
Replies: 0 comments 1 reply
-
附上C++代码const int N = 33;
class Solution {
public:
bool isMatch(string s, string p) {
int m = s.size(), n = p.size();
bool dp[N][N] = {false};
dp[0][0] = true;
for(int i = 1; i <= n; ++i) if(p[i-1] == '*') dp[0][i] = dp[0][i-2];
for(int i = 1; i <= m; ++i) {
for(int j = 1; j <= n; ++j) {
if(s[i-1] == p[j-1] || p[j-1] == '.')
dp[i][j] = dp[i-1][j-1];
else if(p[j-1] == '*') {
if(s[i-1] != p[j-2] && p[j-2] != '.')
dp[i][j] = dp[i][j-2];
else
dp[i][j] = dp[i-1][j] | dp[i][j-2];
}
}
}
return dp[m][n];
}
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
0010. 正则表达式匹配 | 算法通关手册
https://algo.itcharge.cn/Solutions/0001-0099/regular-expression-matching/
Beta Was this translation helpful? Give feedback.
All reactions