-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution24.java
More file actions
41 lines (38 loc) · 1.06 KB
/
Copy pathSolution24.java
File metadata and controls
41 lines (38 loc) · 1.06 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.ArrayList;
import java.util.List;
public class Solution24{
static int factorial(int i){
if(i == 0){
return 1;
}
else{
int result = 1;
for(int j = 1; j <= i; j++){
result *= j;
}
return result;
}
}
public static void main(String[] args) {
String permutation = "";
int remaining = 999999;
List<Integer> numbers = new ArrayList<Integer>();
for(int i = 0; i < 10; i++){
numbers.add(i);
}
for(int i = 1; i < 10;i++){
int j = remaining / factorial(10 - i);
remaining = remaining % factorial(10 - i);
permutation += numbers.get(j);
numbers.remove(j);
if(remaining == 0){
break;
}
}
System.out.println(numbers.toString());
for(int i = 0; i < numbers.size();i++){
permutation = permutation + numbers.get(i);
}
System.out.println(permutation);
}
}