给你一个字符串 sequence ,如果字符串 word 连续重复 k 次形成的字符串是 sequence 的一个子字符串,那么单词 word 的 重复值为 k 。单词 word 的 最大重复值 是单词 word 在 sequence 中最大的重复值。如果 word 不是 sequence 的子串,那么重复值 k 为 0 。
class Solution:
def maxRepeating(self, sequence: str, word: str) -> int:
c = 0
i = 1
while True:
if word * i in sequence:
c += 1
i += 1
if word * i not in sequence:
break
return c