Leetcode 516. 最长回文子序列(DAY 31) ---- 动态规划学习期
发布日期:2021-06-30 22:24:52 浏览次数:2 分类:技术文章

本文共 580 字,大约阅读时间需要 1 分钟。

原题题目

在这里插入图片描述



代码实现(首刷半看解半自解)

int longestPalindromeSubseq(char * s){
int m = strlen(s),start = 0,end = 0,dp[m][m],maxlength = 1; for(end = 0;end < m ;end++) {
for(start = end;start>=0;start--) {
if(end - start <= 1) dp[start][end] = (s[start] == s[end] ? end-start+1 : 1); else dp[start][end] = (s[start] == s[end] ? dp[start+1][end-1]+2 : fmax(dp[start+1][end],dp[start][end-1])); if(dp[start][end] > maxlength) maxlength = dp[start][end]; } } return maxlength;}

转载地址:https://love6.blog.csdn.net/article/details/113245959 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Leetcode 343. 整数拆分(DAY 31) ---- 动态规划学习期
下一篇:Leetcode 1143. 最长公共子序列(DAY 32) ---- 动态规划学习期

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月23日 17时07分11秒