代码:
//找出所有回文子串
public class LongestSubStringV2 {
public static void main(String[] args) {
String str = "ccababdeeeeccdccee";
char[] chs = str.toCharArray();
System.out.println(chs.length);
for (int p = 0; p < chs.length - 0; p++) {
seek(str, chs, p);
}
}
static void seek(String str, char[] chs, int p) {
int i = p - 1;
int j = p + 1;
boolean b = false;
while (i >= 0 && chs[i] == chs[p]) {
b = true;
i--;
}
if (b) {
System.out.println("i= " + (i + 1) + ", p= " + p + ", " + str.substring(i + 1, p + 1));
}
b = false;
while (j < chs.length && chs[p] == chs[j]) {
b = true;
j++;
}
if (b) {
System.out.println("p= " + p + ", j= " + (j - 1) + ", " + str.substring(p, j - 1 + 1));
}
b = false;
while (i >= 0 && j < chs.length && chs[i] == chs[j]) {
i--;
j++;
b = true;
}
if (b) {
System.out.print("i= " + (i + 1) + ", j= " + (j - 1) + ", ");
for (int m = i + 1; m <= j - 1; m++) {
System.out.print(chs[m]);
}
System.out.println();
}
}
}