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”. Java Solution 1 public String shortestPalindrome(String s) { int i=0; int j=s.length()-1; … Read more