Skip to content

Instantly share code, notes, and snippets.

@kanrourou
Created September 25, 2017 05:43
class Solution {
public:
bool repeatedSubstringPattern(string s) {
int len = s.size();
if(!len)return true;
vector<int> next(len + 1, -1);
int i = 0, k = -1;
while(i < len)
{
if(k == -1 || s[i] == s[k])
next[++i] = ++k;
else
k = next[k];
}
return next[len] > 0 && len % (len - next[len]) == 0;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment