All problems

Repeated Substring Pattern

Easy · string matching

You are given a string s of lowercase letters.

Return true if s can be built by taking some block of letters from the start of s and writing it out two or more times in a row, with nothing left over. Otherwise return false.

For example, "abab" is the block "ab" written twice, and "abcabcabc" is "abc" written three times. A string made of a single block, such as "abc", does not count.

Examples

Example 1

Input: s = "abcabcabc"

Output: true

The block "abc" written three times gives the string.

Example 2

Input: s = "abcabcab"

Output: false

Writing "abc" out gives "abcabcabc" or "abcabc", and no block gives exactly this string.

Example 3

Input: s = "aaaa"

Output: true

The block "a" written four times works (so does "aa" twice).

Constraints