diff --git a/Java/Big O/Example_12/Example.java b/Java/Big O/Example_12/Example.java new file mode 100644 index 000000000..096348128 --- /dev/null +++ b/Java/Big O/Example_12/Example.java @@ -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"); + } +}