-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path31.java
More file actions
29 lines (29 loc) · 713 Bytes
/
31.java
File metadata and controls
29 lines (29 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
public void nextPermutation(int[] nums) {
int first_dec=0;
int in=0;
for(int i=nums.length-1;i>0;i-- ){
if(nums[i-1]<nums[i]){
first_dec=i-1;
in=i;
break;
}
}
for(int i=nums.length-1;i>=0;i-- ){
if(nums[i]>nums[first_dec]){
int temp=nums[i];
nums[i]=nums[first_dec];
nums[first_dec]=temp;
break;
}
}
int l=nums.length-1;
while(in<l){
int t=nums[in];
nums[in]=nums[l];
nums[l]=t;
in++;
l--;
}
}
}