From 5000a978fd41dd32a639935459365fd58e691c37 Mon Sep 17 00:00:00 2001 From: jianghongcheng <35664721+jianghongcheng@users.noreply.github.com> Date: Sat, 6 May 2023 20:05:02 -0500 Subject: [PATCH] =?UTF-8?q?Update=200459.=E9=87=8D=E5=A4=8D=E7=9A=84?= =?UTF-8?q?=E5=AD=90=E5=AD=97=E7=AC=A6=E4=B8=B2.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0459.重复的子字符串.md | 39 ++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/problems/0459.重复的子字符串.md b/problems/0459.重复的子字符串.md index 98c02a25..5d56ad18 100644 --- a/problems/0459.重复的子字符串.md +++ b/problems/0459.重复的子字符串.md @@ -264,8 +264,7 @@ class Solution { Python: -这里使用了前缀表统一减一的实现方式 - +(版本一) 前缀表 减一 ```python class Solution: def repeatedSubstringPattern(self, s: str) -> bool: @@ -289,7 +288,7 @@ class Solution: return nxt ``` -前缀表(不减一)的代码实现 +(版本二) 前缀表 不减一 ```python class Solution: @@ -314,6 +313,40 @@ class Solution: return nxt ``` + +(版本三) 使用 find + +```python +class Solution: + def repeatedSubstringPattern(self, s: str) -> bool: + n = len(s) + if n <= 1: + return False + ss = s[1:] + s[:-1] + print(ss.find(s)) + return ss.find(s) != -1 +``` + +(版本四) 暴力法 + +```python +class Solution: + def repeatedSubstringPattern(self, s: str) -> bool: + n = len(s) + if n <= 1: + return False + + substr = "" + for i in range(1, n//2 + 1): + if n % i == 0: + substr = s[:i] + if substr * (n//i) == s: + return True + + return False +``` + + Go: 这里使用了前缀表统一减一的实现方式