用dp来解决比较好理解
状态转移方程dp[j][i]表示以j为起点,i为终点的子串是否为回文串
dp[j][i] = (s[j] == s[i] && s[j + 1][i - 1])
初值
当j == i时,dp[j][i] = true
当i - j = 1时,s[i] == s[j]则dp[j][i] = true
1 | class Solution { |
用dp来解决比较好理解
状态转移方程dp[j][i]表示以j为起点,i为终点的子串是否为回文串
dp[j][i] = (s[j] == s[i] && s[j + 1][i - 1])
初值
当j == i时,dp[j][i] = true
当i - j = 1时,s[i] == s[j]则dp[j][i] = true
1 | class Solution { |