Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.
Example
No.1
Input: “babad”
Output: “bab”
Note: “aba” is also a valid answer.
No.2
Input: “cbbd”
Output: “bb”
O(n^2) runtime, O(n) space – Dynamic programming
1 | public String longestPalindrome(String s) { |
O(n^2) runtime, O(1) space – Simpler solution
1 | public String longestPalindrome(String s) { |