We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2faa84f commit aaf587cCopy full SHA for aaf587c
solution/1053.Previous Permutation With One Swap/Solution.java
@@ -0,0 +1,19 @@
1
+class Solution {
2
+ public int[] prevPermOpt1(int[] A) {
3
+ for (int i = A.length - 2; i >= 0; --i) {
4
+ if (A[i] > A[i + 1]) {
5
+ int k = i + 1;
6
+ for (int j = k + 1; j < A.length; ++j) {
7
+ if (A[j] < A[i] && A[j] > A[k]) {
8
+ k = j;
9
+ }
10
11
+ int t = A[i];
12
+ A[i] = A[k];
13
+ A[k] = t;
14
+ return A;
15
16
17
18
19
+}
0 commit comments