LeetCode – Shortest Palindrome (Java)
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.
For example, given "aacecaaa", return "aaacecaaa"; given "abcd", return "dcbabcd".
Analysis
We can solve this problem by using one of the methods which is used to solve the longest palindrome substring problem.
Specifically, we can start from the center and scan two sides. If read the left boundary, then the shortest palindrome is identified.
Read full article from LeetCode – Shortest Palindrome (Java)
No comments:
Post a Comment