Class Solution
java.lang.Object
g1001_1100.s1053_previous_permutation_with_one_swap.Solution
1053 - Previous Permutation With One Swap.<p>Medium</p>
<p>Given an array of positive integers <code>arr</code> (not necessarily distinct), return <em>the lexicographically largest permutation that is smaller than</em> <code>arr</code>, that can be <strong>made with exactly one swap</strong> (A <em>swap</em> exchanges the positions of two numbers <code>arr[i]</code> and <code>arr[j]</code>). If it cannot be done, then return the same array.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> arr = [3,2,1]</p>
<p><strong>Output:</strong> [3,1,2]</p>
<p><strong>Explanation:</strong> Swapping 2 and 1.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> arr = [1,1,5]</p>
<p><strong>Output:</strong> [1,1,5]</p>
<p><strong>Explanation:</strong> This is already the smallest permutation.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> arr = [1,9,4,6,7]</p>
<p><strong>Output:</strong> [1,7,4,6,9]</p>
<p><strong>Explanation:</strong> Swapping 9 and 7.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= arr.length <= 10<sup>4</sup></code></li>
<li><code>1 <= arr[i] <= 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
prevPermOpt1
public int[] prevPermOpt1(int[] arr)
-