459. Repeated Substring Pattern ¶ Time: $O(n^2)$ Space: $O(n)$ C++JavaPython 1 2 3 4 5 6 7class Solution { public: bool repeatedSubstringPattern(string s) { const string ss = s + s; return ss.substr(1, ss.length() - 2).find(s) != string::npos; } }; 1 2 3 4 5 6class Solution { public boolean repeatedSubstringPattern(String s) { final String ss = s + s; return ss.substring(1, ss.length() - 1).contains(s); } } 1 2 3class Solution: def repeatedSubstringPattern(self, s: str) -> bool: return s in (s + s)[1:-1]