题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/b4525d1d84934cf280439aeecc36f4af
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param A string字符串 * @return int整型 */ int getLongestPalindrome(string A) { // write code here int n = A.size(); vector<vector<bool>> dp(n,vector<bool>(n)); int len =1; for(int i=n-1;i>=0;i--) { for(int j=i;j<n;j++) { if(A[i] == A[j]) { dp[i][j] = i+1 <j?dp[i+1][j-1]:true; } if(dp[i][j] && j-i+1>len) { len = j-i+1; } } } return len ; } };