最长回文子串

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        char[] chrs = scan.nextLine().toCharArray();
        int ans = 1;
        boolean[][] dp = new boolean[chrs.length][chrs.length];
        for (int l = chrs.length - 1; l > -1; l--) {
            for (int r = l; r < chrs.length; r++) {
                if (l == r || (chrs[l] == chrs[r] && (r - l <= 2 || dp[l + 1][r - 1]))) {
                    dp[l][r] = true;
                }
                if (dp[l][r] && r - l + 1 > ans) {
                    ans = r - l + 1;
                }
            }
        }
        System.out.println(ans);
    }
}