class Solution(object):
def maxRepeating(self, sequence, word):
cnt = 0
words = ''
while len(words) <= len(sequence) :
words += word
if words in sequence:
cnt += 1
return cnt
扩展
判断一个子串在列表中出现的次数可以用 count()函数,
list = ['123','234','123']
print(list.count(123))
输出 2