Skip to main content
Back to problems
#459
Easy Algorithms

Repeated substring pattern

String String Matching
47.9% acceptance
Jan 13, 2026
6837
565
Given a string s, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn repeated_substring_pattern(s: String) -> bool {
    let doubled = format!("{}{}", s, s);
    doubled[1..doubled.len()-1].contains(&s)
  }
}