找出给定字符串中最长回文子串:暴力解法
// 最长回文字符串
public StringgetSubString(String s){
if (s =="" || s ==null) {
return "";
}
int max =0;
String s2 =null;
for (int i =0; i < s.length()-1; i++) {
for (int j = i+1; j < s.length(); j++) {
String s1 = s.substring(i,j);
int len = longestPalindrome(s1);
if (len >= max) {
max = len;
s2 = s1;
}
}
}
return s2;
}
// 最长回文字符串
public int longestPalindrome(String s) {
int start =0;
int end = s.length() -1;
while (start <= end){
if (s.charAt(start) == s.charAt(end)) {
start++;
end--;
}else {
return 0;
}
}
return s.length();
}