-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem024.java
More file actions
24 lines (24 loc) · 799 Bytes
/
Problem024.java
File metadata and controls
24 lines (24 loc) · 799 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
import java.util.ArrayList;
import java.util.Collections;
public class Problem024 {
private static ArrayList<String> permute(String s) {
ArrayList<String> perms = new ArrayList<String>();
if (s.length() == 1) {
perms.add(s);
return perms;
}
ArrayList<String> deeper = permute(s.substring(1));
String head = s.substring(0,1);
for (String str : deeper) {
for (int i = 0; i <= str.length(); i++) {
perms.add(str.substring(0, i) + head + str.substring(i));
}
}
return perms;
}
public static void main(String[] args) {
ArrayList<String> perms = permute("0123456789");
Collections.sort(perms);
System.out.println(perms.get(999999));
}
}