public String longestPalindrome(String s) {
        if (s == null || s.length() == 0) {
            return s;
        }

        mapping = new boolean[s.length()][s.length()];
        int maxI = 0;
        int maxJ = 0;
        for (int k = 0; k < s.length(); k++) {
            for (int i = 0; i < s.length() - k; i++) {
                int j = i + k;
                mapping[i][j] = k == 0 || ((s.charAt(i) == s.charAt(j)) && ((k == 1) || mapping[i + 1][j - 1]));
                if (mapping[i][j]) {
                    maxI = i;
                    maxJ = j;
                }
            }
        }

        return s.substring(maxI, maxJ + 1);
    }