【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))
posted @ 2022-01-04 19:20  MoKin_Li  阅读(41)  评论(0编辑  收藏  举报