Longest Duplicate Substring LeetCode solution in Python

1
# Runtime: 2799 ms (Top 43.0%) | Memory: 16.80 MB (Top 93.0%)
2

3

4
class Solution:
5
def longestDupSubstring(self, s: str) -> str:
6
left = 0
7
right = 1
8
res = ""
9
n = len(s)
10
while right < n:
11
if s[left:right] in s[left + 1 :]:
12
if right - left > len(res):
13
res = s[left:right]
14
right += 1
15
continue
16
left += 1
17
if left == right:
18
right += 1
19
return res

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0