1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-11-12 15:25:48 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (English)/大于目标字符串的最小字典序回文排列(English) [lexicographically-smallest-palindromic-permutation-greater-than-target].html
2025-11-11 22:54:49 +08:00

70 lines
3.0 KiB
HTML

<p>You are given two strings <code>s</code> and <code>target</code>, each of length <code>n</code>, consisting of lowercase English letters.</p>
<p>Return the <strong><span data-keyword="lexicographically-smaller-string">lexicographically smallest</span> string</strong> that is <strong>both</strong> a <strong><span data-keyword="palindrome-string">palindromic</span> <span data-keyword="permutation">permutation</span></strong> of <code>s</code> and <strong>strictly</strong> greater than <code>target</code>. If no such permutation exists, return an empty string.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;baba&quot;, target = &quot;abba&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;baab&quot;</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>The palindromic permutations of <code>s</code> (in lexicographical order) are <code>&quot;abba&quot;</code> and <code>&quot;baab&quot;</code>.</li>
<li>The lexicographically smallest permutation that is strictly greater than <code>target</code> is <code>&quot;baab&quot;</code>.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;baba&quot;, target = &quot;bbaa&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;&quot;</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>The palindromic permutations of <code>s</code> (in lexicographical order) are <code>&quot;abba&quot;</code> and <code>&quot;baab&quot;</code>.</li>
<li>None of them is lexicographically strictly greater than <code>target</code>. Therefore, the answer is <code>&quot;&quot;</code>.</li>
</ul>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;abc&quot;, target = &quot;abb&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;&quot;</span></p>
<p><strong>Explanation:</strong></p>
<p><code>s</code> has no palindromic permutations. Therefore, the answer is <code>&quot;&quot;</code>.</p>
</div>
<p><strong class="example">Example 4:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;aac&quot;, target = &quot;abb&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;aca&quot;</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>The only palindromic permutation of <code>s</code> is <code>&quot;aca&quot;</code>.</li>
<li><code>&quot;aca&quot;</code> is strictly greater than <code>target</code>. Therefore, the answer is <code>&quot;aca&quot;</code>.</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n == s.length == target.length &lt;= 300</code></li>
<li><code>s</code> and <code>target</code> consist of only lowercase English letters.</li>
</ul>