diff --git a/problems/0459.重复的子字符串.md b/problems/0459.重复的子字符串.md index bdced0ef..988b2abf 100644 --- a/problems/0459.重复的子字符串.md +++ b/problems/0459.重复的子字符串.md @@ -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