← 返回 reddit 的题目列表Coding 1 - Shortest Palindrome
类型:online_judge
Problem: Shortest Palindrome
Given a string s, you may add characters only to the front of the string to make the whole string a palindrome.
Return the shortest palindrome you can obtain by performing this operation.
Input/Output
Input: a string s
Output: a string representing the shortest palindrome formed by adding characters in front of s
Constraints
0 <= len(s) <= 10^5
Examples
Input: "aacecaaa" Output: "aaacecaaa"
Input: "abcd" Output: "dcbabcd"
Notes
You may only add characters to the beginning of the string.
If multiple ways exist, return the one with minimum length (the result is unique).
Example
Input
aacecaaa
Output
aaacecaaa