Struggling through some of these problems so I can prepare myself. I kind of worked something out. It seems to do it in O(n), but the code turned out so simple that I am skeptical I actually got it. Syntax of some things may not even be right. Anyways, here's my solution.
public static String longestP (String mystring) {
HashMap myhash = new HashMap();
int temp1, temp2;
int i;
int palindromeLength = 0;
String longestPalindrome;
for (i=0;i palindromeLength)) {
palindromeLength = substring.length();
longestPalindrome = substring;
}
}
}
return longestPalindrome;
}