Palindrome: aba abcba
Dual loop through the string, starting from the first layer to find the inner loop from a last start looking. When the memory cycle is equal to the character and the character of the outer layer is composed of the new array, it determines whether or not palindromic
public static void main(String[] args) { String str = "gcgdecdabcdefgfeh"; char[] chars = str.toCharArray(); Map<String,Integer> maxLength = maxLength(chars); System.out.println(maxLength); } 返回结果:{fgf=3, gcg=3, efgfe=5}
// Copy new array Private static char [] copynew ( char [] chars, int Start, int End) { char [] = newchars new new char [Start-End +. 1 ]; int n-= 0 ; for ( int I = Start; I <= End; I ++ ) { newchars [n- ++] = chars [I]; } return newchars; } // determines whether palindromic public static Boolean Check ( char [] chars) { int Start = 0 ; int end = chars.length-1; while (start<end){ if(chars[start]==chars[end]){ start++; end--; }else { return false; } } return true; }