10
Gitea CTest Workflow / test (push) Waiting to run

This commit is contained in:
2026-06-25 20:53:46 +08:00
parent 5f803ed09f
commit f9ac8111cc
3 changed files with 163 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
// This file is generated by mkfile.py
// Date: 2026-06-25
#include <solution/10.h>
#include <stdlib.h>
#include <string.h>
bool char_march(char s, char p)
{
return p == '.' || s == p;
}
bool isMatch(char *s, char *p)
{
size_t m = strlen(s);
size_t n = strlen(p);
bool **dp = malloc(sizeof(bool *) * (m + 1));
for (size_t i = 0; i < (m + 1); i++)
{
dp[i] = malloc(sizeof(bool) * (n + 1));
memset(dp[i], false, sizeof(bool) * (n + 1));
}
dp[0][0] = true;
// s is empty
for (size_t j = 2; j <= n; j++)
{
if (p[j - 1] == '*')
dp[0][j] = dp[0][j - 2];
}
for (size_t i = 1; i <= m; i++)
{
for (size_t j = 1; j <= n; j++)
{
if (p[j - 1] != '*')
{
dp[i][j] = dp[i - 1][j - 1] && char_march(s[i - 1], p[j - 1]);
}
else
{
dp[i][j] = dp[i][j - 2];
if (char_march(s[i - 1], p[j - 2]))
dp[i][j] = dp[i][j] || dp[i - 1][j];
}
}
}
bool matched = dp[m][n];
for (size_t i = 0; i <= m; i++)
{
free(dp[i]);
}
free(dp);
return matched;
}