@@ -0,0 +1,1575 @@
+//5. Longest Palindromic Substring%0A/**%0A * Given a string s, find the longest palindromic substring in s. %0A * You may assume that the maximum length of s is 1000.%0A * %0A * Example:%0A * Input: %22babad%22%0A * Output: %22bab%22%0A * Note: %22aba%22 is also a valid answer.%0A * %0A * Example:%0A * Input: %22cbbd%22%0A * Output: %22bb%22%0A * %0A * Tags: String%0A * Similar Problems: (H) Shortest Palindrome (E) Palindrome Permutation (H) Palindrome Pairs%0A * %0A * @author Xinyue Zhang%0A *%0A */%0Apublic class Solution %7B%0A    public String longestPalindrome(String s) %7B%0A        int n = s.length();%0A        if (n %3C 2) return s;%0A        %0A        int start = 0, i = 0, maxLen = 0;%0A        //the max length is 2 * (n - i)%0A        while (i %3C n - 1 && maxLen %3C 2 * (n - i)) %7B%0A            int left = i, right = i;%0A            //skip duplicates, which are palindromic string%0A            while (right %3C n - 1 && s.charAt(right) == s.charAt(right + 1)) %0A                right++;%0A            %0A            i = right + 1; %0A            %0A            while (left %3E 0 && right %3C n - 1 && s.charAt(left - 1) == s.charAt(right + 1)) %7B%0A                left--;%0A                right++;%0A            %7D%0A            //update max length%0A            int curLen = right - left + 1;%0A            if (curLen %3E maxLen) %7B%0A                maxLen = curLen;%0A                start = left;%0A            %7D  %0A        %7D%0A        %0A        return s.substring(start, start + maxLen);%0A    %7D%0A    %0A    public static void main(String args%5B%5D) %7B%0A        String s = %22babbad%22;%0A        Solution sol = new Solution();%0A        System.out.println(sol.longestPalindrome(s));%0A    %7D%0A%7D%0A

Add solution for 5. Longest Palindromic Substring