java.lang.Object
g2601_2700.s2697_lexicographically_smallest_palindrome.Solution

public class Solution extends Object
2697 - Lexicographically Smallest Palindrome.<p>Easy</p> <p>You are given a string <code>s</code> consisting of <strong>lowercase English letters</strong> , and you are allowed to perform operations on it. In one operation, you can <strong>replace</strong> a character in <code>s</code> with another lowercase English letter.</p> <p>Your task is to make <code>s</code> a <strong>palindrome</strong> with the <strong>minimum</strong> <strong>number</strong> <strong>of operations</strong> possible. If there are <strong>multiple palindromes</strong> that can be made using the <strong>minimum</strong> number of operations, make the <strong>lexicographically smallest</strong> one.</p> <p>A string <code>a</code> is lexicographically smaller than a string <code>b</code> (of the same length) if in the first position where <code>a</code> and <code>b</code> differ, string <code>a</code> has a letter that appears earlier in the alphabet than the corresponding letter in <code>b</code>.</p> <p>Return <em>the resulting palindrome string.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;egcfe&rdquo;</p> <p><strong>Output:</strong> &ldquo;efcfe&rdquo;</p> <p><strong>Explanation:</strong> The minimum number of operations to make &ldquo;egcfe&rdquo; a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is &ldquo;efcfe&rdquo;, by changing &lsquo;g&rsquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;abcd&rdquo;</p> <p><strong>Output:</strong> &ldquo;abba&rdquo;</p> <p><strong>Explanation:</strong> The minimum number of operations to make &ldquo;abcd&rdquo; a palindrome is 2, and the lexicographically smallest palindrome string we can get by modifying two characters is &ldquo;abba&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;seven&rdquo;</p> <p><strong>Output:</strong> &ldquo;neven&rdquo;</p> <p><strong>Explanation:</strong> The minimum number of operations to make &ldquo;seven&rdquo; a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is &ldquo;neven&rdquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 1000</code></li> <li><code>s</code> consists of only lowercase English letters**.**</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • makeSmallestPalindrome

      public String makeSmallestPalindrome(String s)