1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/交换一次的先前排列 [previous-permutation-with-one-swap].html

39 lines
1.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个正整数数组 <code>arr</code>(可能存在重复的元素),请你返回可在&nbsp;<strong>一次交换</strong>(交换两数字 <code>arr[i]</code><code>arr[j]</code> 的位置)后得到的、按字典序排列小于 <code>arr</code> 的最大排列。</p>
<p>如果无法这么操作,就请返回原数组。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>arr = [3,2,1]
<strong>输出:</strong>[3,1,2]
<strong>解释:</strong>交换 2 和 1
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>arr = [1,1,5]
<strong>输出:</strong>[1,1,5]
<strong>解释:</strong>已经是最小排列
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>arr = [1,9,4,6,7]
<strong>输出:</strong>[1,7,4,6,9]
<strong>解释:</strong>交换 9 和 7
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= arr.length &lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= arr[i] &lt;= 10<sup>4</sup></code></li>
</ul>