0459.cpp (427B)
1 class Solution { 2 public: 3 bool repeatedSubstringPattern(const string &s) { 4 string made; 5 for (int i = 1; i <= s.size() / 2; i++) { 6 if (s.size() % i) continue; 7 const string pref = s.substr(0, i); 8 for (int j = 0; j < s.size() / i; j++) 9 made += pref; 10 if (made == s) return true; 11 made.clear(); 12 } 13 return false; 14 } 15 };