Update 0459.重复的子字符串,添加C#版

This commit is contained in:
eeee0717
2023-11-07 09:40:37 +08:00
parent 4500cbd9bd
commit 69cc985a7c

View File

@ -681,6 +681,32 @@ impl Solution {
}
}
```
### C#
```C#
// 前缀表不减一
public bool RepeatedSubstringPattern(string s)
{
if (s.Length == 0)
return false;
int[] next = GetNext(s);
int len = s.Length;
if (next[len - 1] != 0 && len % (len - next[len - 1]) == 0) return true;
return false;
}
public int[] GetNext(string s)
{
int[] next = Enumerable.Repeat(0, s.Length).ToArray();
for (int i = 1, j = 0; i < s.Length; i++)
{
while (j > 0 && s[i] != s[j])
j = next[j - 1];
if (s[i] == s[j])
j++;
next[i] = j;
}
return next;
}
```
<p align="center">