手机网站图片锚链接怎么做,网络营销效果评估的作用有哪些,自己给公司做网站该怎么做,淘宝联盟填网站备案题目#xff1a;给定字符串#xff0c;求其最长的回文子串说明#xff1a;给定字符串长度为1000以内。思路#xff1a;for循环遍历字符串#xff0c;求以i为中心的回文子串长度。与最长回文子串长度max_len比较#xff0c;若大于max_len#xff0c;则更新max_len。说明给定字符串求其最长的回文子串说明给定字符串长度为1000以内。思路for循环遍历字符串求以i为中心的回文子串长度。与最长回文子串长度max_len比较若大于max_len则更新max_len。说明注意分开处理子串长度为奇偶的两种情况时间复杂度O(N2)。代码 class Solution {
public:string longestPalindrome(string s) {int len_ss.size();int max_len0;int cen_pos0;bool flagfalse;for(int i0;ilen_s;i){int cur_len0;while((i-cur_len)0 (icur_len)len_s s[i-cur_len]s[icur_len])cur_len;if(cur_lenmax_len){max_len(cur_len-1);cen_posi;flagfalse;}cur_len0;while((i-cur_len-1)0 (icur_len)len_s s[i-cur_len-1]s[icur_len])cur_len;if(cur_lenmax_len){max_lencur_len;cen_posi;flagtrue;}}if(flag)return s.substr(cen_pos-max_len,2*max_len);return s.substr(cen_pos-max_len,2*max_len1);}
}; 转载于:https://www.cnblogs.com/dreamer123/p/9159633.html