Class Solution
-
- All Implemented Interfaces:
public final class Solution2697 - Lexicographically Smallest Palindrome.
Easy
You are given a string
sconsisting of lowercase English letters , and you are allowed to perform operations on it. In one operation, you can replace a character inswith another lowercase English letter.Your task is to make
sa palindrome with the minimum number of operations possible. If there are multiple palindromes that can be made using the minimum number of operations, make the lexicographically smallest one.A string
ais lexicographically smaller than a stringb(of the same length) if in the first position whereaandbdiffer, stringahas a letter that appears earlier in the alphabet than the corresponding letter inb.Return the resulting palindrome string.
Example 1:
Input: s = "egcfe"
Output: "efcfe"
Explanation: The minimum number of operations to make "egcfe" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is "efcfe", by changing 'g'.
Example 2:
Input: s = "abcd"
Output: "abba"
Explanation: The minimum number of operations to make "abcd" a palindrome is 2, and the lexicographically smallest palindrome string we can get by modifying two characters is "abba".
Example 3:
Input: s = "seven"
Output: "neven"
Explanation: The minimum number of operations to make "seven" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is "neven".
Constraints:
1 <= s.length <= 1000sconsists of only lowercase English letters**.**
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final StringmakeSmallestPalindrome(String s)-
-
Method Detail
-
makeSmallestPalindrome
final String makeSmallestPalindrome(String s)
-
-
-
-