5_Longest Palindromic Substring
5. Longest Palindromic Substring
Level: medium
Tag: string, dynamic programming
Question
Note: A palindrome is a word, which reads the same backward as forward.
Idea: (expand around center, dynamic programming)
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
Complexity
Time:
Space: if the length of the longest palindromic substring is constant.
Solution: (bottom-up)
Last updated