问题分析:
在做题的过程中,发现还是需要注意到很多细节的,比如遍历的时候不能对每个索引进行判断,这样就不是连续子串了。在这个问题的回复,我发现了一个十分牛的思路,直接上代码吧,一般人应该都能看懂,或许可以应对大部分连续子串类的问题。
代码:
class Solution {
public int maxRepeating(String sequence, String word) {
int count = 0;
String str = word;
while(sequence.contains(word)){
word += str;
count++;
}
return count;
}
}