LEETCODE ALGORITHM:5.Longest Palindromic Substring
题目
Given a string
s
, return the longest palindromic substring ins
.Example 1:
1
2
3Input: s = "babad"
Output: "bab"
Explanation: "aba" is also a valid answer.Example 2:
1
2Input: s = "cbbd"
Output: "bb"Constraints:
1 <= s.length <= 1000
s
consist of only digits and English letters.
题解
Dp转移方程
\(P(i,j)=P(i+1,j-1)\wedge(S_i==S_j)\)
边界条件
\(P(i,i)=true\)
\(P(i,i+1)=(S_i==S_{i+1})\)
1 | class Solution { |