代码拉取完成,页面将自动刷新
package LeetCode;
public class LC_5 {
public static String longestPalindrome(String s) {
//if (s.length() == 1) return s;
int start = 0;
int maxLen = 1;
boolean[][] dp = new boolean[s.length()][s.length()];
for (int i = s.length() - 1; i >= 0; i--) {
dp[i][i] = true;
for (int j = i + 1; j < s.length(); j++) {
if (s.charAt(i) == s.charAt(j)) {
if (j - i <= 1) {
dp[i][j] = true;
if (maxLen < j - i + 1) {
maxLen = j - i + 1;
start = i;
}
} else if (dp[i + 1][j - 1]) {
dp[i][j] = true;
if (maxLen < j - i + 1) {
maxLen = j - i + 1;
start = i;
}
}
}
System.out.println("i= " + i + " ,j= " + j + " ,start = " + start + " ,maxLen= " + maxLen);
}
System.out.println(dp[1][3]);
}
return s.substring(start, start + maxLen);
}
public static void main(String[] args) {
System.out.println(longestPalindrome("aaaaa"));
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。