Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example 12 of the Big O chapter that prints all permutations of a str… #249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Java/Big O/Example_12/Example.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Example_12;

public class Example {

void permutation(String str) {
permutation(str, "");
}

void permutation(String str, String prefix){
if(str.length() == 0){
System.out.println(prefix);
} else {
for(int i = 0; i < str.length(); i++){
String rem = str.substring(0, i) + str.substring(i + 1);
permutation(rem, prefix + str.charAt(i));
}
}
}

public static void main(String[] args) {
Example ex = new Example();
ex.permutation("abcd");
}
}