mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 15:31:43 +08:00
50 lines
1.8 KiB
HTML
50 lines
1.8 KiB
HTML
<p>You are given a <strong><span data-keyword="palindrome-string">palindromic</span></strong> string <code>s</code>.</p>
|
|
|
|
<p>Return the <strong><span data-keyword="lexicographically-smaller-string">lexicographically smallest</span></strong> palindromic <span data-keyword="permutation-string">permutation</span> of <code>s</code>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">s = "z"</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">"z"</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>A string of only one character is already the lexicographically smallest palindrome.</p>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">s = "babab"</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">"abbba"</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>Rearranging <code>"babab"</code> → <code>"abbba"</code> gives the smallest lexicographic palindrome.</p>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">s = "daccad"</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">"acddca"</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>Rearranging <code>"daccad"</code> → <code>"acddca"</code> gives the smallest lexicographic palindrome.</p>
|
|
</div>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
|
<li><code>s</code> consists of lowercase English letters.</li>
|
|
<li><code>s</code> is guaranteed to be palindromic.</li>
|
|
</ul>
|