Files
LeetCode/Easy/repeated-substring-pattern/solution.cpp
Arkaprabha Chakraborty cab1180397 Refactor almost everything
2022-08-02 12:21:43 +05:30

28 lines
703 B
C++

#include <string>
class Solution {
public:
bool repeatedSubstringPattern(std::string s) {
for (int i = 1; i <= s.size() / 2; ++i) {
std::string sl(s.substr(0, i));
if (s.size() % i == 0) {
bool found = false;
for (int j = 1; j < s.size() / i; ++j) {
if (s.find(sl, sl.size() * j) == sl.size() * j) {
found = true;
} else {
found = false;
break;
}
}
if (found) {
return true;
}
}
}
return false;
}
};