考完試之后躺平了一段時間侦讨,中間斷斷續(xù)續(xù)刷SQL題也懶得記錄摧找,慢慢恢復(fù)刷題節(jié)奏养交。
今日簡單題:https://leetcode.cn/problems/maximum-repeating-substring/
題目比較簡單抓狭,用暴力法可以幾行代碼就完成:
class Solution {
public int maxRepeating(String sequence, String word) {
int count=0;
String tmp=word;
while(sequence.contains(word)){
word+=tmp;
count++;
}
return count;
}
}
看題解發(fā)現(xiàn)其實考的是KMP算法(學(xué)習(xí)了一下沒有非常懂枚抵,先記錄下來)
https://oi-wiki.org/string/kmp/