Skip to content

Commit 1210aaf

Browse files
authored
Create Print permutations of a string
1 parent a506bb5 commit 1210aaf

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Given a string, find and print all the possible permutations of the input string.
3+
Note : The order of permutations are not important. Just print them in different lines.
4+
5+
Sample Input :
6+
abc
7+
Sample Output :
8+
abc
9+
acb
10+
bac
11+
bca
12+
cab
13+
cba
14+
*/
15+
public class solution {
16+
17+
public static void permutations(String input){
18+
// Write your code here
19+
permutationsHelper(input,"");
20+
21+
}
22+
23+
private static void permutationsHelper(String input, String output)
24+
{
25+
if (input.length()==0)
26+
System.out.println(output);
27+
28+
for (int i=0;i<input.length();i++)
29+
permutationsHelper(input.substring(0,i)+input.substring(i+1), output+input.charAt(i));
30+
}
31+
}

0 commit comments

Comments
 (0)