Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- knakul853
- **/
- class Solution {
- public:
- bool repeatedSubstringPattern(string s) {
- int n = (int)s.size();
- vector<int>dp(n, 0);
- for(int i=1;i<n;i++)
- {
- int j = dp[i-1];
- while(j>=1 && s[i] != s[j] )j = dp[j-1];
- if(s[i] == s[j])
- {
- j++;
- }
- dp[i] = j;
- }
- return dp[n-1] && dp[n-1] % (n - dp[n-1]) == 0;
- }
- };
Add Comment
Please, Sign In to add comment