美文网首页
2022-11-03 「1668. 最大重复子字符串」

2022-11-03 「1668. 最大重复子字符串」

作者: 柠香萌萌鸡 | 来源:发表于2022-11-02 09:18 被阅读0次

考完试之后躺平了一段时间,中间断断续续刷SQL题也懒得记录,慢慢恢复刷题节奏。
今日简单题: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;
    }
}

看题解发现其实考的是KMP算法(学习了一下没有非常懂,先记录下来)
https://oi-wiki.org/string/kmp/

相关文章

网友评论

      本文标题:2022-11-03 「1668. 最大重复子字符串」

      本文链接:https://www.haomeiwen.com/subject/wagstdtx.html