<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) {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        vector<int> index;
        for(int i=1; i<=s.size()/2; i++) {
            if(s[i] == s[0]) index.push_back(i);
        }

        int k = 0,j=INT_MIN;
        for(int i=0; i<index.size(); i++) {
            if(index[i]<j) continue;
            int pattern_length = index[i] - k;
            string sub_string = s.substr(k, pattern_length);
            //cout<<sub_string<<endl;
            j = pattern_length;
            while(j < s.size()) {
                string sub_string1 = s.substr(j, pattern_length);
                if(sub_string == sub_string1) {
                    j += pattern_length;
                }else {
                    j -= pattern_length;
                    break;
                }
            }
            if(j==s.size()) return true;
        }
        return false;
    }
};
 // extract 'go' from 'iamgoodhere'
//  string s = "iamgoodhere";
//  int start = 3, end = 4;
//  cout<<s.substr(start,end-start+1); // go
51971