The Repeated Substring Pattern solutions are below.
15 Jun 2024•Easy•C++ / Python / TypeScript
Repeated Substring Pattern
C++, Python and TypeScript solutions for Repeated Substring Pattern.
Solution files
Python•repeated-substring-pattern/synced-solution.py
def repeatedSubstringPattern(s):
return s in (s + s)[1:-1]
C++•repeated-substring-pattern/synced-solution.cpp
class Solution {
public:
bool repeatedSubstringPattern(string s) {
string doubled = s + s;
return doubled.substr(1, 2 * s.length() - 2).find(s) != string::npos;
}
};
TypeScript•repeated-substring-pattern/synced-solution.ts
function repeatedSubstringPattern(s: string): boolean {
const doubled = s + s;
return doubled.substring(1, 2 * s.length - 1).includes(s);
}