diff --git a/problems/0459.重复的子字符串.md b/problems/0459.重复的子字符串.md index 177c3878..3245d948 100644 --- a/problems/0459.重复的子字符串.md +++ b/problems/0459.重复的子字符串.md @@ -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; +} +```