Repeated Substring Pattern

Easy

Description

Given a string s, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Return true if so, false otherwise.

Examples

Input:s = "abab"
Output:true
Explanation:

ab repeated twice forms abab.

Input:s = "aba"
Output:false
Explanation:

No repeated substring can form "aba". The possible substrings "a" and "ab" do not produce "aba" when repeated.

Input:s = "abcabcabcabc"
Output:true
Explanation:

The substring "abc" repeated 4 times produces "abcabcabcabc".

Constraints

  • 1 ≤ s.length ≤ 10⁴

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!