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

2022-11-02  本文已影响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/

上一篇 下一篇

猜你喜欢

热点阅读