画重点:
1.字符串连续重复k次出现,只需循环判断子字符串是否包含在字符串里,字符串的长度是否大于原字符串即可
2.每次循环,字符串都要累加
class Solution {
public int maxRepeating(String sequence, String word) {
int count = 0;
String str = word;
while(sequence.contains(str)&&str.length()<=sequence.length()){
count++;
str +=word;
}
return count;
}
}
哈哈哈哈,这个是不是说明我算法效率很高啊