package com.anuragkapur.leetcode;

/**
 * @author anuragkapur
 */
public class LongestPalindromeSubstring {

    public String longestPalindrome(String s) {

        if (s == null || s.length() == 1) {
            return s;
        }

        final char chars[] = s.toCharArray();
        int longestLength = 0;
        int longestStart = 0;

        for (int i = 0; i < s.length(); i++) {
            for (int j = s.length() - 1; j > i && (j - i + 1) > longestLength; j--) {
                if (isPalindrome(chars, i, j)) {
                    longestStart = i;
                    longestLength = j - i + 1;
                    break;
                }
            }
        }

        return new String(chars, longestStart, longestLength);
    }

    private boolean isPalindrome(final char chars[], int start, int end) {

        if (start > end) {
            throw new IllegalArgumentException("Invalid char array indices provided :: " + start + " , "+ end);
        }

        while (start < end) {
            if (chars[start] != chars[end]) {
                return false;
            }
            start ++;
            end --;
        }

        return true;
    }
}

@@ -98,24 +98,126 @@
 ubstring %7B%0A%0A
+    /**%0A     * Run time complexity: O(n%5E2) (worst case)%0A     *%0A     * @param s%0A     * @return%0A     */%0A
     public S

Add note on run time complexity for LongestPalindromeSubstring problem