题解 | #密码截取#

密码截取

https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();

        int n = str.length();
        boolean[][] dp = new boolean[n][n];

        int max = 0;
        for(int i = 0; i < n; i++){
            for(int j = 0; j <= i; j++){
                if(str.charAt(j) == str.charAt(i) && (i - j < 2 || dp[j + 1][i - 1] == true)){
                    dp[j][i] = true;
                    max = Math.max(max,i - j + 1);
                }
            }
        }

        System.out.println(max);
    }
}

全部评论

相关推荐

09-22 15:45
门头沟学院 Java
谁给娃offer我给...:我也遇到了,我说只要我通过面试我就去,实际上我根本就不会去😁
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务