Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

Shortest Palindrome

LeetCode Problem

Problem Description

Given a string s, you can convert it to a palindrome by adding characters in front of it.

Return the shortest palindrome you can find by performing this transformation.

Note:

  • A palindrome is a string that reads the same forward and backward
  • You can only add characters to the front of the string

Examples

Example 1:

Input: s = "aacecaaa"
Output: "aaacecaaa"

Example 2:

Input: s = "abcd"
Output: "dcbabcd"

Constraints

  • 0 <= s.length <= 5 * 10⁴
  • s consists of lowercase English letters only