leetcode516】的更多相关文章

Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000. Example 1:Input: "bbbab" Output: 4 One possible longest palindromic subsequence is "bbbb". Example 2:Input:…
public class Solution { public int LongestPalindromeSubseq(string s) { int[,] dp = new int[s.Length, s.Length]; ; i >= ; i--) { dp[i, i] = ; ; j < s.Length; j++) { if (s[i] == s[j]) { dp[i, j] = dp[i + , j - ] + ; } else { dp[i, j] = Math.Max(dp[i +…
思路: 区间dp. 实现: class Solution { public: int longestPalindromeSubseq(string s) { int n = s.length(); ][]; ; i < n; i++) { dp[i][i] = ; ) dp[i][i + ] = (s[i] == s[i + ] ? : ); } ; i >= ; i--) { ; j < n; j++) { ][j - ] + ; ][j], dp[i][j - ]); } } ][n…