Update 0459.重复的子字符串.md

This commit is contained in:
jianghongcheng
2023-05-06 20:05:02 -05:00
committed by GitHub
parent e8b4db9d7a
commit 5000a978fd

View File

@ -264,8 +264,7 @@ class Solution {
Python Python
这里使用了前缀表统一减一的实现方式 (版本一) 前缀表 减一
```python ```python
class Solution: class Solution:
def repeatedSubstringPattern(self, s: str) -> bool: def repeatedSubstringPattern(self, s: str) -> bool:
@ -289,7 +288,7 @@ class Solution:
return nxt return nxt
``` ```
前缀表不减一)的代码实现 (版本二) 前缀表 不减一
```python ```python
class Solution: class Solution:
@ -314,6 +313,40 @@ class Solution:
return nxt 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 Go
这里使用了前缀表统一减一的实现方式 这里使用了前缀表统一减一的实现方式