leetcode 459重复的子字符串

class Solution {
public:
    bool repeatedSubstringPattern(string s) {
        int n=s.size();
        if(n==1)
            return false;
        int i=1;
        while(i<=n/2)
        {
            if(n%i==0)
            {
                if(isFormsub(s,i))
                    return true;   
            }
            i++;
        }
        return false;
    }
    bool isFormsub(string s,int i)
    {
        for(int j=0;j<i;++j)
        {
            for(int p=0;j+p*i<s.size();p++)
            {
                if(s[j]!=s[j+p*i])
                    return false;
            }
        }
        return true;
    }
};
static const auto __=[]()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    return 0;
}();

猜你喜欢

转载自blog.csdn.net/fys465253658/article/details/81209012