public class huiwen {
//判断字符串s[i...j]是否为回文串——dp O(n²)
public static boolean[][] isPailn(String str) {
boolean[][] mat = new boolean[str.length()][str.length()];
for (int i = str.length() - 1; i >= 0; i--) {
for (int j = i; j < str.length(); j++) {
if (j == i) {
//单字符为回文字符串
mat[i][j] = true;
} else if (j == i + 1) {
//相邻字符若相同则为回文字符串
mat[i][j] = (str.charAt(i) == str.charAt(j));
} else {
mat[i][j] = (str.charAt(i) == str.charAt(j)) && mat[i + 1][j - 1];
}
}
}
return mat;
}
}
07-02
3749