Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.
input ababcdgje
output aba or bab
/*
for 循环 字符串长度
写一个制定中间数 往两边扩大比较是否一样的方法(判断是否越界)
两种情况 两个方法 aba 和 abba 比较哪个子串长
*/
class Solution {
public String longestPalindrome(String s) {
String ans = new String();
for(int i = 0; i < s.length(); i ++){
String str1 = getPalindromic(s, i, i);
String str2 = getPalindromic(s, i, i+1);
if(str1.length() < str2.length()){
ans = (ans.length() > str2.length()) ? ans : str2;
}
else{
ans = (ans.length() > str1.length()) ? ans : str1;
}
}
return ans;
}
public String getPalindromic(String s, int first, int last){
while(first >= 0 && last