leetcode516
Posted AsenYang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode516相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
[leetcode-516-Longest Palindromic Subsequence]