> For the complete documentation index, see [llms.txt](https://coding-9.gitbook.io/untitled/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coding-9.gitbook.io/untitled/string/easy/459.-repeated-substring-pattern.md).

# 459. Repeated Substring Pattern

## Problem Statement

<br>

Given a string `s`, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.

&#x20;

**Example 1:**

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

**Example 2:**

<pre><code><strong>Input: s = "aba"
</strong><strong>Output: false
</strong></code></pre>

**Example 3:**

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

&#x20;

**Constraints:**

* `1 <= s.length <= 104`
* `s` consists of lowercase English letters.

## Intuition

```
Approach 1:
Take substrings and repeat to check if exists

Approach 2:

s = abab
Repeat and delete first and last character
abab + abab

a)bababa(b
Now try to find abab in this 
```

### Links

<https://leetcode.com/problems/repeated-string-match/description/>

### Video Links

### Approach 1:

```
Brute
```

{% code title="C++" lineNumbers="true" %}

```cpp
class Solution {
public:
    bool repeatedSubstringPattern(string s) {
        int n = s.size();

        for(int i=1; i<=n/2; i++){
            if(n%i == 0){
                string temp = s.substr(0,i);
                string repeat = "";

                for(int j=0; j<n/i; j++){
                    repeat += temp;
                }

                if(repeat == s)
                    return true;
            }
        }

        return false;
    }
};
```

{% endcode %}

### Approach 2:

```
Optimal trick
```

{% code title="C++" lineNumbers="true" %}

```cpp
class Solution {
public:
    bool repeatedSubstringPattern(string s) {
        string rept = s + s;
        string monk = rept.substr(1, rept.size()-2);

        if(monk.find(s) != -1)
            return true;

        return false;
    }
};
```

{% endcode %}

### Approach 3:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
```

{% endcode %}

### Approach 4:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
```

{% endcode %}

### Similar Problems

###
