-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStringPermutation.java
More file actions
28 lines (25 loc) · 900 Bytes
/
Copy pathStringPermutation.java
File metadata and controls
28 lines (25 loc) · 900 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
public class StringPermutation {
public static void main(String[] args) {
String str = "asfa";
boolean visited[] = new boolean[str.length()];
char characters[] = new char[str.length()];
permutaion(str, visited, characters, str.length(), 0);
}
public static void permutaion(String str, boolean visited[], char characters[], int bound, int depth){
if (depth == bound){
for (int i = 0; i < bound; i++) {
System.out.print(characters[i]);
}
System.out.println();
return;
}
for (int i = 0; i < bound; i++) {
if (visited[i] != true){
visited[i] = true;
characters[depth] = str.charAt(i);
permutaion(str, visited, characters, bound, depth + 1);
visited[i] = false;
}
}
}
}