Class Solution

java.lang.Object
g1301_1400.s1328_break_a_palindrome.Solution

public class Solution extends Object
1328 - Break a Palindrome.<p>Medium</p> <p>Given a palindromic string of lowercase English letters <code>palindrome</code>, replace <strong>exactly one</strong> character with any lowercase English letter so that the resulting string is <strong>not</strong> a palindrome and that it is the <strong>lexicographically smallest</strong> one possible.</p> <p>Return <em>the resulting string. If there is no way to replace a character to make it not a palindrome, return an <strong>empty string</strong>.</em></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, <code>a</code> has a character strictly smaller than the corresponding character in <code>b</code>. For example, <code>&quot;abcc&quot;</code> is lexicographically smaller than <code>&quot;abcd&quot;</code> because the first position they differ is at the fourth character, and <code>'c'</code> is smaller than <code>'d'</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> palindrome = &ldquo;abccba&rdquo;</p> <p><strong>Output:</strong> &ldquo;aaccba&rdquo;</p> <p><strong>Explanation:</strong> There are many ways to make &ldquo;abccba&rdquo; not a palindrome, such as &ldquo;zbccba&rdquo;, &ldquo;aaccba&rdquo;, and &ldquo;abacba&rdquo;. Of all the ways, &ldquo;aaccba&rdquo; is the lexicographically smallest.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> palindrome = &ldquo;a&rdquo;</p> <p><strong>Output:</strong> &quot;&quot;</p> <p><strong>Explanation:</strong> There is no way to replace a single character to make &ldquo;a&rdquo; not a palindrome, so return an empty string.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= palindrome.length <= 1000</code></li> <li><code>palindrome</code> consists of only lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • breakPalindrome

      public String breakPalindrome(String palindrome)