1 Star 0 Fork 0

唐梓迅/leetcode题解

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
剑指offer19 648 Bytes
Copy Edit Raw Blame History
唐梓迅 authored 2022-12-03 20:07 +08:00 . 正则表达式匹配
class Solution {
public:
bool isMatch(string s, string p) {
int n = s.size() + 1;
int m = p.size() + 1;
vector<vector<bool>> dp(n,vector<bool>(m,0));
dp[0][0] = true;
for(int j=2;j<m;j += 2)
dp[0][j] = dp[0][j-2] && p[j-1] == '*';
for(int i=1;i<n;i++)
{
for(int j=1;j<m;j++)
{
dp[i][j] = p[j-1] == '*' ?
dp[i][j-2] || dp[i-1][j] && (s[i-1] == p[j-2] || p[j-2] == '.') :
dp[i-1][j-1] && (p[j-1] == '.' || s[i-1] == p[j-1]);
}
}
return dp[n-1][m-1];
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/Tang-CMer/leetcode-problem-solving.git
git@gitee.com:Tang-CMer/leetcode-problem-solving.git
Tang-CMer
leetcode-problem-solving
leetcode题解
master

Search