leetcode459. 重复的子字符串

1、题目

https://leetcode-cn.com/problems/repeated-substring-pattern/

2、题意

题解1:枚举

class Solution {
public:
    bool repeatedSubstringPattern(string s) {
        int n = s.size(),j;
        s = " "+s;
        for(int i=1;i<=n/2;i++)
        {
            if(n%i==0)
            {
                for(j=i+1;j<=n;j+=i)
                {
                    if(s.substr(1,i)!=s.substr(j,i))
                        break;
                }
                if(j>n)
                    return true;
            }
        }
        return false;
    }
};

你可能感兴趣的:(leetcode)