Merge pull request #2863 from Cwlrin/master

docs:补充【0459.重复的子字符串.md】的 JavaScript 、C# 代码
This commit is contained in:
程序员Carl
2025-02-13 19:06:51 +08:00
committed by GitHub

View File

@ -689,6 +689,29 @@ var repeatedSubstringPattern = function (s) {
}; };
``` ```
> 正则匹配
```javascript
/**
* @param {string} s
* @return {boolean}
*/
var repeatedSubstringPattern = function(s) {
let reg = /^(\w+)\1+$/
return reg.test(s)
};
```
> 移动匹配
```javascript
/**
* @param {string} s
* @return {boolean}
*/
var repeatedSubstringPattern = function (s) {
let ss = s + s;
return ss.substring(1, ss.length - 1).includes(s);
};
```
### TypeScript: ### TypeScript:
> 前缀表统一减一 > 前缀表统一减一
@ -894,8 +917,10 @@ impl Solution {
} }
``` ```
### C# ### C#
> 前缀表不减一
```csharp ```csharp
// 前缀表不减一
public bool RepeatedSubstringPattern(string s) public bool RepeatedSubstringPattern(string s)
{ {
if (s.Length == 0) if (s.Length == 0)
@ -920,6 +945,13 @@ public int[] GetNext(string s)
} }
``` ```
> 移动匹配
```csharp
public bool RepeatedSubstringPattern(string s) {
string ss = (s + s).Substring(1, (s + s).Length - 2);
return ss.Contains(s);
}
```
### C ### C
```c ```c