classSolution: defmaxRepeating(self, sequence: str, word: str) -> int: result = repeat_time = i = flag = 0 word_len = len(word) s_len = len(sequence) sequence += " " * word_len # 防止下标越界罢了 while i < s_len: if sequence[i] == word[0]: # 如果当前字母和word首字母相同 while sequence[i: i + word_len] == word: flag = 1 i = i + word_len repeat_time += 1# 重复次数+1 ifnot flag: i += 1 else: i = i - word_len + 1 flag = 0 result = max(result, repeat_time) repeat_time = 0 continue i += 1 return result