5_Longest Palindromic Substring
Last updated
Last updated
Level: medium
Tag: string, dynamic programming
Note: A palindrome is a word, which reads the same backward as forward.
Loop from the beginning to the end. Take each letter be the center of the substring, and find maximum length substring centered by each letter.
There are two types of center:
the letter is the center, such that the palindromic substring has odd number of letters
the space on the right of the letter is the center, such that the palindromic substring has even number of letters
Time:
Space: if the length of the longest palindromic substring is constant.