File tree 2 files changed +33
-1
lines changed
solution/0000-0099/0031.Next Permutation
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 9
9
/lcof /lcof.json
10
10
/lcof /lcof_list.json
11
11
/lcci /lcci.json
12
- /solution /__pycache__
12
+ /solution /__pycache__
13
+ * .iml
Original file line number Diff line number Diff line change
1
+ type sortInt []int
2
+
3
+ func (s sortInt ) Len () int {
4
+ return len (s )
5
+ }
6
+
7
+ func (s sortInt ) Less (i , j int ) bool {
8
+ return s [i ] > s [j ]
9
+ }
10
+
11
+ func (s sortInt ) Swap (i , j int ) {
12
+ s [i ], s [j ] = s [j ], s [i ]
13
+ }
14
+
15
+ func nextPermutation (nums []int ) {
16
+ newNums := sortInt (nums )
17
+ if sort .IsSorted (newNums ) {
18
+ n := sort .Reverse (newNums )
19
+ sort .Sort (n )
20
+ return
21
+ }
22
+ for i := len (nums ) - 2 ; i >= 0 ; i -- {
23
+ for j := len (nums ) - 1 ; j > i ; j -- {
24
+ if nums [i ] < nums [j ] {
25
+ nums [i ],nums [j ] = nums [j ], nums [i ]
26
+ sort .Sort (sort .Reverse (newNums [i + 1 :]))
27
+ return
28
+ }
29
+ }
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments