Longest Palindromic Substring Nov 11 '11
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.
public class Solution { public String longestPalindrome(String s) { // Start typing your Java solution below // DO NOT write main() function int sz = s.length(); if(sz<=1) return s; int[][] d = new int[sz][sz]; for(int i=0; ilongest) { longest = d[i][i+1]; start = i; } } } for(int len=2; len longest ) { longest = d[i][j]; start = i; } } else { d[i][j] = 0; } } } return s.substring(start, start+longest); }}