mirror of
https://github.com/arkorty/LeetCode.git
synced 2026-03-18 00:57:17 +00:00
Refactor almost everything
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#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;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user