题解 | #密码截取#
密码截取
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
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(yxzfccd(zfc)); } private static int yxzfccd(String zfc){ int sz=0; boolean dtpd[][] =new boolean[zfc.length()][zfc.length()]; if(zfc.length()<=0){ sz=0; } for(int i=0;i<zfc.length();i++){ dtpd[i][i]=true; sz=1; } for(int i=0;i<zfc.length()-1;i++){ if(zfc.charAt(i)==zfc.charAt(i+1)){ dtpd[i][i+1]=true; } } for(int l=3;l<=zfc.length();l++){ for(int i=0;i<=zfc.length()-l;i++){ int j = i+l-1; if(zfc.charAt(i)==zfc.charAt(j)&&dtpd[i+1][j-1]){ dtpd[i][j]=true; sz = Math.max(sz,l); } } } return sz; } }