题解 | #最长无重复子数组#
最长回文子串
http://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
public class Main {//优化的中心点扩散法 public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextLine()) { String str=sc.nextLine(); int len=str.length(),max=Integer.MIN_VALUE; int i=0; while(i<len) { int left=i-1; int right=i; while(++right<len&&str.charAt(right)==str.charAt(i)); //如 abbbbba i=1指向b, right就直接循环到第二个a的下标 i=right; while(left>=0&&right<len&&str.charAt(left)==str.charAt(right)) { left--; right++; } max=Math.max(max, right-left-1); } System.out.println(max); } sc.close(); } }