import java.util.Scanner;
/**
* Created by Administrator on 2017/8/12.
* 如果一个01串任意两个相邻位置的字符都不一样,称为01串
* 输出最长的子串长度
* 解法:最笨的o(n^2);
*/
public class wangyiFirst {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str;
int max = 0;
//while (sc.hasNext()) {
//}
str = sc.next();
max = sovle(str);
System.out.print(max);
}
private static int sovle(String str) {
int max = 0;
for (int i = 0; i < str.length(); i++) {
int sum = 0;
int index = 0;
char q = str.charAt(i);
for (int j = i + 1; j < str.length(); j++) {
if (str.charAt(j) == q) {
index = j - i;
break;
}else {
q = str.charAt(j);
index = j - i + 1;
}
}
max = Math.max(max, index);
}
return max;
}
}
网易内推2017最长01子串
最新推荐文章于 2020-08-09 21:18:33 发布