随笔分类 -  字符串

最长回文子序列 leetcode 516
摘要:class Solution { public: int longestPalindromeSubseq(string s) { int len=s.size(); if(len==0) return 0; vector<vector<int>> dp(len,vector<int>(len,1)) 阅读全文

posted @ 2020-03-09 18:33 QingFengDaHui 阅读(131) 评论(0) 推荐(0)

leetcode 5 最长回文子串(马拉车算法)
摘要:添加‘#’的原因是让偶数回文串也可以有中心点,添加‘!’和’?’的原因是防止len数组越界 其中len[i]表示以i为中心时,从i到以i为中心的回文串的最右边的长度 mx表示循环到此时之前所有的回文串的右边界的最大值,p表示该回文串的中心 class Solution { public: strin 阅读全文

posted @ 2020-03-09 18:30 QingFengDaHui 阅读(198) 评论(0) 推荐(0)

leetcode 28(简单kmp)
摘要:void GetNext(string &needle,int next[]) { next[0]=-1; int k=-1; int len=needle.size(); for(int i=1;i<len;i++) { while(k!=-1&&needle[k+1]!=needle[i]) k 阅读全文

posted @ 2020-03-09 18:24 QingFengDaHui 阅读(223) 评论(0) 推荐(0)

导航