Skip to content

Commit 68be926

Browse files
committed
200218 algorithm
1 parent 3e6c64c commit 68be926

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.ArrayList;
2+
import java.util.Arrays;
3+
import java.util.List;
4+
5+
class Solution {
6+
long f[] = new long[21];
7+
public int[] solution(int n, long k) {
8+
int[] answer = new int[n];
9+
make_f();
10+
List<Integer> list = new ArrayList<>();
11+
for(int i=0;i<n;i++){
12+
list.add(i+1);
13+
}
14+
int x = 0;
15+
for(int i=0;i<n;i++){
16+
x = (int)((k-1)/f[n-1-i]);
17+
answer[i] = list.remove(x);
18+
k = k-(x*f[n-1-i]);
19+
}
20+
return answer;
21+
}
22+
public void make_f(){
23+
f[0] = 1;
24+
for(int i=1;i<=20;i++){
25+
f[i] = f[i-1]*(long)i;
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)