Maximum Repeating Substring LeetCode solution in Python

1
# Runtime: 61 ms (Top 15.28%) | Memory: 13.8 MB (Top 62.83%)
2
class Solution:
3
def maxRepeating(self, sequence: str, word: str) -> int:
4
if word not in sequence:
5
return 0
6

7
left = 1
8
right = len(sequence) // len(word)
9
while left <= right:
10
mid = (left + right) // 2
11
if word * mid in sequence:
12
left = mid + 1
13
else:
14
right = mid - 1
15

16
return left - 1

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0