mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-11 21:10:58 +08:00
Merge pull request #2863 from Cwlrin/master
docs:补充【0459.重复的子字符串.md】的 JavaScript 、C# 代码
This commit is contained in:
@ -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:
|
||||
|
||||
> 前缀表统一减一
|
||||
@ -894,8 +917,10 @@ impl Solution {
|
||||
}
|
||||
```
|
||||
### C#
|
||||
|
||||
> 前缀表不减一
|
||||
|
||||
```csharp
|
||||
// 前缀表不减一
|
||||
public bool RepeatedSubstringPattern(string s)
|
||||
{
|
||||
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
|
||||
|
Reference in New Issue
Block a user