Easy

Quiz

#459 Repeated Substring Pattern

APPROACH

Given a string s, check whether it can be written as a shorter pattern repeated at least twice consecutively (using only proper substrings of s). Return true if so, false otherwise.

Example 1:

Input: s = "abab"
Output: true
Explanation: It is the substring "ab" twice.

Example 2:

Input: s = "aba"
Output: false

Example 3:

Input: s = "abcabcabcabc"
Output: true
Explanation: It is the substring "abc" four times or the substring "abcabc" twice.
1 of 4
1:00

What is the optimal approach for this problem?