#459
Repeated Substring Pattern
pupil · 455 · lc easy +26 · verified · 47.9% accepted · 6,841 likes · top 33%
Description
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.
Code
1
2
3