题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
import java.util.*; public class Main { public static void main(String[] args) { Scanner fzhinput = new Scanner(System.in); String zfc = fzhinput.nextLine(); System.out.println(xzlongdc(zfc)); } private static int xzlongdc(String zfc){ int maxlength=0; for(int i=0;i<zfc.length();i++){ for(int j=i;j<zfc.length();j++){ if(sfdc(zfc,i,j)){ maxlength = Math.max(maxlength,j-i+1); } } } return maxlength; } private static boolean sfdc(String zfc, int l, int r){ while(l<r){ if(zfc.charAt(l)!=zfc.charAt(r)){ return false; } l++; r--; } return true; } }