This commit is contained in:
2025-12-05 21:59:22 +08:00
parent e580f911cb
commit e862aea336
3 changed files with 100 additions and 0 deletions

37
src/1668.c Normal file
View File

@@ -0,0 +1,37 @@
// This file is generated by mkfile.py
// Date: 2025-12-05
#include <solution/1668.h>
#include <stdbool.h>
#include <string.h>
#define max(x, y) ((x) > (y) ? (x) : (y))
int maxRepeating(char *sequence, char *word)
{
int n = strlen(sequence), m = strlen(word);
if (n < m)
return 0;
int dp[n];
for (int i = m - 1; i < n; i++)
{
bool valid = true;
for (int j = 0; j < m; j++)
{
if (sequence[i - m + 1] != word[j])
{
valid = false;
break;
}
}
if (valid)
dp[i] = (i == m - 1 ? 0 : dp[i - m] + 1);
}
int ret = dp[0];
for (int i = 1; i < n; i++)
ret = max(ret, dp[i]);
return ret;
}