程序媛詹妮弗
终身学习

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".

 

题意:

找出给定字符串中的最长回文子序列

 

Solution1: DP

1.  state: dp[i][j] stands for the length of longest panlin subsequences in substring[i,j] inclusively 

2. function:  

if s[i] = s[j] ,  dp[i][j] = dp[i+1][j-1] + 2

if s[i] != s[j],  dp[i][j] = MAX(d[i+1][j] , dp[i][j-1])

 

 

code

 

posted on 2019-05-07 03:10  程序媛詹妮弗  阅读(99)  评论(0编辑  收藏  举报