https://leetcode-cn.com/problems/longest-palindromic-substring/
    中心扩散法

    1. class Solution {
    2. public String longestPalindrome(String s) {
    3. if(s.length() == 0){
    4. return null;
    5. }
    6. int res = 1;
    7. int ll =0;
    8. int rr = 0;
    9. for(int i = 0; i<s.length(); i++){
    10. //奇数
    11. int l = i-1;
    12. int r = i+1;
    13. while(l>=0&&r<s.length() &&s.charAt(l) == s.charAt(r)){
    14. int len = r - l +1;
    15. if(len > res){
    16. res = len;
    17. ll = l;
    18. rr = r;
    19. }
    20. l--;
    21. r++;
    22. }
    23. //偶数
    24. l = i;
    25. r = i+1;
    26. while(l>=0&&r<s.length() &&s.charAt(l) == s.charAt(r)){
    27. int len = r - l +1;
    28. if(len > res){
    29. res = len;
    30. ll = l;
    31. rr = r;
    32. }
    33. l--;
    34. r++;
    35. }
    36. }
    37. return s.substring(ll, rr+1);
    38. }
    39. }