标签:ali max lin ret == for leetcode pre str
最长回文子串
解题思想:动态规划
class Solution { public String longestPalindrome(String s) { int len = s.length(); boolean[][] b = new boolean[len][len]; int max = 0; int begin = 0; for(int i=0;i<len;i++){ for(int j=0;j<=i;j++){ if(s.charAt(i)==s.charAt(j)&&(i-j<=2 || b[j+1][i-1])){ b[j][i] = true; if(i-j+1>max){ max = i - j + 1; begin = j; } } } } return s.substring(begin,begin+max); } }
标签:ali max lin ret == for leetcode pre str
原文地址:https://www.cnblogs.com/erdanyang/p/11068367.html