31. Shortest Palindrome(Imp)
Minimum addition to make string palindrome
You are given a string s
. You can convert s
to a palindrome by adding characters in front of it.
Return the shortest palindrome you can find by performing this transformation.
Example 1:
Example 2:
Approach:
If we find the maximum length palindromic substring from front. We can add reverse of the right part to make it palindrome. To find maximum length palindrome in O(n +m) time
Solution: (Comparing every possible length)
Time Complexity: O(n * n)
Solution: ()
Last updated