题解 | #最长重复子串#
最长重复子串
https://www.nowcoder.com/practice/4fe306a84f084c249e4afad5edf889cc
# 暴力枚举
```python
class Solution:
def solve(self , a: str) -> int:
res = 0
# 枚举起始点
for i in range(len(a)-1):
# 枚举长度
for j in range(1, (len(a)//2)+1):
if self.check(a, i, j):
res = max(res, 2*j)
return res
def check(self,a, i, j):
if i+2*j-1>len(a)-1:
return False
left, right = i, i+j
for x in range(j):
if a[left+x]!=a[right+x]:
return False
return True
def solve(self , a: str) -> int:
res = 0
# 枚举起始点
for i in range(len(a)-1):
# 枚举长度
for j in range(1, (len(a)//2)+1):
if self.check(a, i, j):
res = max(res, 2*j)
return res
def check(self,a, i, j):
if i+2*j-1>len(a)-1:
return False
left, right = i, i+j
for x in range(j):
if a[left+x]!=a[right+x]:
return False
return True
```