首页 > 其他 > 详细

leetcode516

时间:2017-06-09 09:24:14      阅读:176      评论:0      收藏:0      [点我收藏+]
public class Solution {
    public int LongestPalindromeSubseq(string s) {
        int[,] dp = new int[s.Length, s.Length];

            for (int i = s.Length - 1; i >= 0; i--)
            {
                dp[i, i] = 1;
                for (int j = i + 1; j < s.Length; j++)
                {
                    if (s[i] == s[j])
                    {
                        dp[i, j] = dp[i + 1, j - 1] + 2;
                    }
                    else
                    {
                        dp[i, j] = Math.Max(dp[i + 1, j], dp[i, j - 1]);
                    }
                }
            }
            return dp[0, s.Length - 1];
    }
}

https://leetcode.com/problems/longest-palindromic-subsequence/#/description

leetcode516

原文:http://www.cnblogs.com/asenyang/p/6970296.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!