Skip to content

Commit 205925f

Browse files
committed
feat: create No.1053
1 parent 92139d7 commit 205925f

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# 1053. Previous Permutation With One Swap
2+
3+
- Difficulty: Medium.
4+
- Related Topics: Array, Greedy.
5+
- Similar Questions: .
6+
7+
## Problem
8+
9+
Given an array of positive integers ```arr``` (not necessarily distinct), return **the ****lexicographically**** largest permutation that is smaller than** ```arr```, that can be **made with exactly one swap**. If it cannot be done, then return the same array.
10+
11+
**Note** that a **swap** exchanges the positions of two numbers ```arr[i]``` and ```arr[j]```
12+
13+
 
14+
Example 1:
15+
16+
```
17+
Input: arr = [3,2,1]
18+
Output: [3,1,2]
19+
Explanation: Swapping 2 and 1.
20+
```
21+
22+
Example 2:
23+
24+
```
25+
Input: arr = [1,1,5]
26+
Output: [1,1,5]
27+
Explanation: This is already the smallest permutation.
28+
```
29+
30+
Example 3:
31+
32+
```
33+
Input: arr = [1,9,4,6,7]
34+
Output: [1,7,4,6,9]
35+
Explanation: Swapping 9 and 7.
36+
```
37+
38+
 
39+
**Constraints:**
40+
41+
42+
43+
- ```1 <= arr.length <= 104```
44+
45+
- ```1 <= arr[i] <= 104```
46+
47+
48+
49+
## Solution
50+
51+
```javascript
52+
53+
```
54+
55+
**Explain:**
56+
57+
nope.
58+
59+
**Complexity:**
60+
61+
* Time complexity : O(n).
62+
* Space complexity : O(n).

0 commit comments

Comments
 (0)