1. 题目
读题
考查点
2. 解法
思路
代码逻辑
具体实现
public class HJ085 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(longestParaline(sc.nextLine()));
}
public static int longestParaline(String str) {
int n = str.length();
boolean[][] dp = new boolean[n][n];
int maxlen = 1;
for (int len = 1; len <= n; len++) {
for (int i = 0; i < n - len + 1; i++) {
int j = i + len - 1;
if (len == 1) {
dp[i][j] = true;
} else if (len == 2) {
dp[i][j] = str.charAt(i) == str.charAt(j);
} else {
dp[i][j] = dp[i + 1][j - 1] && str.charAt(i) == str.charAt(j);
}
if (dp[i][j] && len > maxlen) {
maxlen = len;
}
}
}
return maxlen;
}
}