https://leetcode-cn.com/problems/longest-palindromic-substring/
中心扩散法
class Solution {
public String longestPalindrome(String s) {
if(s.length() == 0){
return null;
}
int res = 1;
int ll =0;
int rr = 0;
for(int i = 0; i<s.length(); i++){
//奇数
int l = i-1;
int r = i+1;
while(l>=0&&r<s.length() &&s.charAt(l) == s.charAt(r)){
int len = r - l +1;
if(len > res){
res = len;
ll = l;
rr = r;
}
l--;
r++;
}
//偶数
l = i;
r = i+1;
while(l>=0&&r<s.length() &&s.charAt(l) == s.charAt(r)){
int len = r - l +1;
if(len > res){
res = len;
ll = l;
rr = r;
}
l--;
r++;
}
}
return s.substring(ll, rr+1);
}
}