Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000.
Answer
Original
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14
classSolution { public: boolrepeatedSubstringPattern(string str){ for (int i = str.size() / 2; i >= 1; --i) { if (str.size() % i == 0) { string t; for (int j = 0; j != str.size() / i; ++j) t += str.substr(0, i); if (t == str) returntrue; } } returnfalse; } };