<p>Given a string <code>s</code>, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;abab&quot;
<strong>Output:</strong> true
<strong>Explanation:</strong> It is the substring &quot;ab&quot; twice.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;aba&quot;
<strong>Output:</strong> false
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;abcabcabcabc&quot;
<strong>Output:</strong> true
<strong>Explanation:</strong> It is the substring &quot;abc&quot; four times or the substring &quot;abcabc&quot; twice.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 10<sup>4</sup></code></li>
	<li><code>s</code> consists of lowercase English letters.</li>
</ul>

class Solution {
public:
    bool repeatedSubstringPattern(string s) {
        string str;
        string str2;
        string dup=s;
        int count=0;

        for(int i=0;i<(s.length()/2);i++){
            str+=s[i];
            dup=s;
            count=0;
            int prev=-1;
            if(s.length()%(i+1)==0){
                for(int j=0;j<(s.length()/str.length());j++){
                    int ind = dup.find(str);
                    if(ind != string::npos){
                        count++;
                        dup = dup.substr(ind+str.length());
                        prev=ind;
                    }
                    if(ind>=1&&ind != prev+str.length()){
                        break;
                    }
                }
                if(count*str.length()==s.length()){
                    return true;
                }
            }
        }
        return false;
    }
};
420903