Problem Statement
A palindrome is a string that reads the same from left to right as it does from right to left. Given a String s, return the shortest palindrome that can be produced by adding zero or more characters to the right end of s. There is always one unique answer.
Definition
- Class:
- Palindromize
- Method:
- minAdds
- Parameters:
- String
- Returns:
- String
- Method signature:
- String minAdds(String s)
- (be sure your method is public)
Constraints
- s will contain between 1 and 50 characters, inclusive.
- Each character of s will be a lowercase letter ('a'-'z').
Examples
"add"
Returns: "adda"
Add 'a' to make a palindrome. "adddda" is also a valid palindrome, but it is not the shortest possible one."cigartragic"
Returns: "cigartragic"
This is already a palindrome, so the shortest solution is to add 0 letters."redocpot"
Returns: "redocpotopcoder"
"acaba"
Returns: "acabaca"
"abczyxyz"
Returns: "abczyxyzcba"