昆山做网站好的,wordpress 安装 插件,上海人才引进官网,怎样做化妆品网站思路#xff1a;
KMP算法的核心是求next数组
next数组代表的是当前字符串最大前后缀的长度
而求重复的子字符串就是求字符串的最大前缀与最大后缀之间的子字符串
如果这个子字符串是字符串长度的约数#xff0c;则true /** lc appleetcode.cn id459 langcpp** [459] 重复…思路
KMP算法的核心是求next数组
next数组代表的是当前字符串最大前后缀的长度
而求重复的子字符串就是求字符串的最大前缀与最大后缀之间的子字符串
如果这个子字符串是字符串长度的约数则true /** lc appleetcode.cn id459 langcpp** [459] 重复的子字符串*/// lc codestart
class Solution {
public:void getNext(string s,std::vectorint next){next[0] 0;int j 0;for(int i 1;is.size();i){while(j0 s[j]! s[i]) j next[j-1];if(s[i] s[j]) j;next[i] j;}}bool repeatedSubstringPattern(string s) {//初始化next数组//遍历next数组统计0出现的次数index用s.size()-index//如果next数组最后一位是s.size()-index则true//否则falsestd::vectorint next(s.size());getNext(s,next);int len s.size();int longestPre next[len-1];if(longestPre 0 len%(len-longestPre) 0){return true;}return false;}
};
// lc codeend