@@ -0,0 +1,1746 @@
+public class Solution %7B%0A    public String longestPalindrome(String s) %7B%0A        String manacherStr = preProcess(s);%0A    %0A        int center = 0;%0A        int radius = 0;%0A        int%5B%5D manacherP = new int%5BmanacherStr.length()%5D;%0A        for(int i = 1; i %3C manacherStr.length() - 1; i++)%7B%0A            int iMirror = 2 * center - i;%0A    %0A            if(iMirror %3E= 0 && iMirror %3C manacherStr.length())%7B%0A                manacherP%5Bi%5D = radius %3E i ? Math.min(radius - i, manacherP%5BiMirror%5D) : 0;%0A            %7D%0A    %0A            int left = i - 1 - manacherP%5Bi%5D;%0A            int right = i + 1 + manacherP%5Bi%5D;%0A            while(manacherStr.charAt(left) == manacherStr.charAt(right))%7B%0A                left--;%0A                right++;%0A                manacherP%5Bi%5D++;%0A    %0A                if(left %3C 0 %7C%7C right %3E= manacherStr.length())%7B%0A                    break;%0A                %7D%0A            %7D%0A    %0A            if(i + manacherP%5Bi%5D %3E radius)%7B%0A                center = i;%0A                radius = i + manacherP%5Bi%5D;%0A            %7D%0A        %7D%0A    %0A        int maxLen = 0;%0A        int centerIndex = 0;%0A        for(int i = 1; i %3C manacherStr.length() - 1; i++)%7B%0A            if(manacherP%5Bi%5D %3E maxLen)%7B%0A                maxLen = manacherP%5Bi%5D;%0A                centerIndex = i;%0A            %7D%0A        %7D%0A    %0A        int start = (centerIndex - maxLen - 1) / 2;%0A        int end = start + maxLen;%0A        return s.substring(start, end);%0A    %7D%0A%0A    private String preProcess(String s)%7B%0A        if(s.length() == 0)%7B%0A            return %22%5E$%22;%0A        %7D%0A    %0A        StringBuilder sb = new StringBuilder(%22%5E%22);%0A    %0A        for(int i = 0; i %3C s.length(); i++)%7B%0A            sb.append(%22#%22 + s.charAt(i));%0A        %7D%0A    %0A        sb.append(%22#$%22);%0A    %0A        return sb.toString();%0A    %7D%0A%7D

Q5 Longest Palindromic Substring