题解 | #最长回文子串#
最长回文子串
http://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); String line=sc.nextLine(); String s; int max=0; for(int i=0;i<line.length();i++){ for(int j=line.length();j>i;j--){ s=line.substring(i,j); if(line.length()-i<max) break; if(check(s)&&s.length()>max) max=s.length(); } } System.out.println(max); } public static boolean check(String s){ return s.equals(new StringBuilder(s).reverse().toString()); } }