llllmz

导航

459. 重复的子字符串

KMP算法一点都不想回忆了,等找实习的时候再仔细看吧

class Solution {
public:
    bool repeatedSubstringPattern(string s) {
        if(s.size() <= 1) return false;
        string temp = "", str = "";
        for(int i = 0; i < s.size() / 2; ++i){
            temp += s[i];
            while(str.size() <= s.size()){
                str += temp;
                if(str == s) return true;
            }
            str = "";
        }
        return false;
    }
};

 

posted on 2024-10-21 23:33  神奇的萝卜丝  阅读(2)  评论(0编辑  收藏  举报