mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Update 0459.重复的子字符串,添加C#版
This commit is contained in:
@ -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">
|
<p align="center">
|
||||||
|
Reference in New Issue
Block a user