Longest Palindromic Substring

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.

DP: O(n^2) in both time and space. chk[i, j] = true if and only if s[i] == s[j] and chk[i-1, j+1] = true. Also note that the loop should NOT be i from 0 to n-1 and j from 0 to n-1.
Redo in 2014-01-15. O(1) in space and O(n^2) in time.

Comments

Popular posts from this blog

Maximum Gap

[ITint5] Maximum Subarray for a Circular Array

[CC150] Chapter 8 Object-Oriented Design