Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69cc985

Browse files
committed
Update 0459.重复的子字符串,添加C#版
1 parent 4500cbd commit 69cc985

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎problems/0459.重复的子字符串.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,32 @@ impl Solution {
681681
}
682682
}
683683
```
684+
### C#
685+
```C#
686+
// 前缀表不减一
687+
public bool RepeatedSubstringPattern(string s)
688+
{
689+
if (s.Length == 0)
690+
return false;
691+
int[] next = GetNext(s);
692+
int len = s.Length;
693+
if (next[len - 1] != 0 && len % (len - next[len - 1]) == 0) return true;
694+
return false;
695+
}
696+
public int[] GetNext(string s)
697+
{
698+
int[] next = Enumerable.Repeat(0, s.Length).ToArray();
699+
for (int i = 1, j = 0; i < s.Length; i++)
700+
{
701+
while (j > 0 && s[i] != s[j])
702+
j = next[j - 1];
703+
if (s[i] == s[j])
704+
j++;
705+
next[i] = j;
706+
}
707+
return next;
708+
}
709+
```
684710

685711

686712
<p align="center">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /