【LeetCode】1668.最大重复子字符串(三)

4、使用count()方法

Python count() 方法用于统计字符串里某个字符或子字符串出现的次数。可选参数为在字符串搜索的开始与结束位置。

>>> str='aaabaaaabaaabaaaabaaaabaaaabaaaaba' 
>>> substr='aaaba'
>>> str.count(substr)
6
>>> str.count('12')   
0
>>>

count()语法:

str.count(sub, start= 0,end=len(string))
原文地址:https://www.cnblogs.com/LeeCookies/p/15763717.html