参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()) { String s = scanner.next(); int n = s.length(); if(n < 2) { System.out.println(n); continue; } int start = 0, end = 0; int res = 1; for(int i = 0; i < n; i++) { int len1 = find(s, i, i); int len2 = find(s, i, i + 1); res = Math.max(res, Math.max(len1, len2)); } System.out.println(res); } } public static int find(String s, int i, int j) { while(i >= 0 && j < s.length() && s.charAt(i) == s.charAt(j)) { i--; j++; } return j - i - 1; } }
0.0分
4 人评分
C语言考试练习题_一元二次方程 (C语言代码)浏览:733 |
哥德巴赫曾猜测 (C语言代码)浏览:994 |
数组输出 (C语言代码)--此题的题目描述有问题浏览:1814 |
IP判断 (C语言描述,蓝桥杯)浏览:1094 |
1128题解(返回值为数组的情况)浏览:450 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:696 |
1035 题解浏览:778 |
C二级辅导-公约公倍 (C语言代码)浏览:481 |
1197求助浏览:627 |
青年歌手大奖赛_评委会打分 (C语言代码)浏览:2139 |