题解 | #最长回文子串#

最长回文子串

http://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507

import java.util.*;

public  class Main {
        public static int value = Integer.MAX_VALUE;
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            String s = sc.nextLine();
            int max =0;
            for(int i=0;i<s.length();i++){
                for(int j = s.length();j>i;j--){
                    String judege = s.substring(i,j);
                    if(isJudge(judege)){
                        max = Math.max(max,j-i);
                    }
                }
            }
            System.out.println(max);
        }
        public static boolean isJudge(String s){
            return s.equals(new StringBuilder(s).reverse().toString());
        }
    
}
全部评论

相关推荐

你背过凌晨4点的八股文么:简历挂了的话会是流程终止,像我一样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务